I get a status 200 when connecting to the websocket, but it is an error?

Please check http://procbits.com/connecting-to-a-sockjs-server-from-native-html5-websocket! After you append /websocket (to your URL), it will give you the error Failed to parse Origin header value [null] 😉 , which then will in turn lead you to that link. You’ll have to add .setAllowedOrigins(“*”) to your addHandler() method, and then it could finally work!

Spring WebSocket @SendToSession: send message to specific session

No need to create specific destinations, it’s already done out of the box as of Spring 4.1 (see SPR-11309). Given users subscribe to a /user/queue/something queue, you can send a message to a single session with: As stated in the SimpMessageSendingOperations Javadoc, since your user name is actually a sessionId, you MUST set that as … Read more

Where “user” comes from in convertAndSendToUser works in SockJS+Spring Websocket?

We know we can send messages to the client from a stomp server using the topic prefixes that he is subscribed to e.g. /topic/hello. We also know we can send messages to a specific user because spring provides the convertAndSendToUser(username, destination, message) API. It accepts a String username which means if we somehow have a … Read more

Does Spring @SubscribeMapping really subscribe the client to some topic?

By default the return value from an @SubscribeMapping method is sent as a message directly back to the connected client and does not pass through the broker. (emphasis mine) Here the Spring Framework documentation is describing what happens with the response message, not the incoming SUBSCRIBE message. So to answer your questions: yes, the client … Read more

How WebSocket server handles multiple incoming connection requests?

Your question is great! I would like to try to answer it from the point of view involving the system calls listen() and accept(). Understanding the behavior of these two calls I think is quite insightful and sufficient to answer your question. Spoiler: we can answer your question by looking into how TCP/IP works 🙂 … Read more

What are the pitfalls of using Websockets in place of RESTful HTTP?

With RESTful HTTP you have a stateless request/response system where the client sends request and server returns the response. With webSockets you have a stateful (or potentially stateful) message passing system where messages can be sent either way and sending a message has a lower overhead than with a RESTful HTTP request/response. The two are … Read more

Sending message to specific user on Spring Websocket

Oh, client side no need to known about current user, server will do that for you. On server side, using following way to send message to an user: simpMessagingTemplate.convertAndSendToUser(username, “/queue/reply”, message); Note: Using queue, not topic, Spring always using queue with sendToUser On client side stompClient.subscribe(“/user/queue/reply”, handler); Explain When any websocket connection is open, Spring … Read more