Which is better: multiple web socket endpoints or a single web socket endpoint in Java EE7

Java EE 7 makes creating new endpoints very easy through annotations. However, I was wondering if there are several endpoints for processing each type of message, a good idea, or do I have only one end facade for everything?

I tend to have one single end facade, based on the theory that each end point creates a new socket connection with the client. However, this theory may not be correct, and the Web Socket can be implemented in such a way that it will use only one TCP / IP socket connection, regardless of how many end points of the web socket are connected while they are connecting to the same host: port .

I am asking specifically for Java EE 7, as there may be other web socket server implementations that can do something different.

+7
source share
2 answers

The only valid answer here is the last option - having multiple endpoints.

See WebSocket chaper 2.1.3 specification :

The API restricts the registration of MessageHandlers per session as one MessageHandler per native message type in the form of websocket. [WSC 2.1.3-1] In other words, a developer can register at most one message for incoming text messages, one MessageHandler for incoming binary messages, and one MessageHandler for incoming messages. The websocket implementation should generate an error if this restriction is violated [WSC 2.1.3-2].

As for using or not using multiple TCP connections - AFAIK will currently have a new connection for each client, and there is no easy way how you can force anything else. WebSocket multiplexing should solve it, but I don’t think support for its WebSocket API (I could be wrong ..)

+4
source

Just noticed the ambiguity in my question re: message types. When I talk about message types, I was referring to different types of application messages, not ordinary message types such as "binary" or "text." So I marked @PavelBucek's answer as accepted.

However, I tried an experiment with Glassfish and had two endpoints. My suspicions were correct and that a TCP connection was established on each connected endpoint. This will result in more server load if more than one websocket endpoint is used on the same page.

Thus, I came to the conclusion that there should only be one endpoint for processing application messages, provided that everything is the only native type.

This would mean that the application must dispatch and not rely on some higher level API to do this for us.

+5
source

All Articles