Uses port 80 / 443 (URL scheme: ws:// and wss://) • Small overhead for text messages (frames) • 0x00 for frame start, 0xFF for frame end (vs HTTP 1Kb) • Ping / pong frames for staying alive 9
WebSocket? I want you to talk to me as well! HTTP 101 Yes! Talk WebSocket to me! WebSocket here’s a frame WebSocket here’s a frame WebSocket here’s a frame close connection
When the connection is open, send some data to the server ws.onopen = function () { ws.send('Here I am!'); }; ws.onmessage = function (event) { console.log('message: ' + event.data); }; ws.onclose = function (event) { console.log('closed:' + event.code); };
of plain JSR-‐356? • Fallback options with SockJS • Support for STOMP subprotocol • Security (with Spring Security) • Integration with messaging components and Spring programming style 13
public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint(“/ws") } ... } .withSockJS(); Use SockJS for fallback options
STOMP semantics • Return values are sent to a STOMP message broker via the brokerChannel (doesn’t apply to @SubscriptionMapping) • can be the built-‐in simple broker • or a full blown message broker
STOMP commands • Stores everything in memory • SimpleBrokerMessageHandler will be subscribed to inboundClientChannel and brokerChannel 21 @Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableSimpleBroker("/queue/", "/topic/"); registry.setApplicationDestinationPrefixes("/app"); }