Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Java EE 7 allows you to create new endpoints very easily through annotations. However, I was wondering is having multiple endpoints one to handle each message type a good idea or should I have just one endpoint facade for everything?

I am leaning towards having one single end-point facade based on the theory that each endpoint creates a new socket connection to the client. However, that theory could be incorrect and Web Socket may be implemented so that it will use just one TCP/IP socket connection regardless of how many web socket end points are connected so long as they connect to the same host:port.

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

like image 916
Archimedes Trajano Avatar asked Jun 24 '13 16:06

Archimedes Trajano


People also ask

Can you have multiple WebSockets?

A server can open WebSocket connections with multiple clients—even multiple connections with the same client. It can then message one, some, or all of these clients. Practically, this means multiple people can connect to our chat app, and we can message some of them at a time.

Are WebSockets Faster Than REST API?

Fast Reaction TimeWebSockets allow for a higher amount of efficiency compared to REST because they do not require the HTTP request/response overhead for each message sent and received.

Do WebSockets have endpoints?

The Web Socket Endpoint represents an object that can handle websocket conversations. Developers may extend this class in order to implement a programmatic websocket endpoint. The Endpoint class holds lifecycle methods that may be overridden to intercept websocket open, error and close events.

Which is faster WebSocket or HTTP?

All the frequently updated applications used WebSocket because it is faster than HTTP Connection. When we do not want to retain a connection for a particular amount of time or reuse the connection for transmitting data; An HTTP connection is slower than WebSockets.


1 Answers

Just noticed an ambiguity on my question re: message types. When I say message types I meant different kinds of application messages not native message types such as "binary" or "text". As such I marked @PavelBucek answer as the accepted one.

However, I did try an experiment with Glassfish and having two end points. My suspicions were correct and that there is a TCP connection established per connected endpoint. This would cause more load on the server side if there is more than one websocket endpoint being used on a single page.

As such I concluded that there should be only one endpoint to handle the application messages provided that everything is a single native type.

This would mean that the application needs to do the dispatching rather than relying on some higher level API to do it for us.

like image 108
Archimedes Trajano Avatar answered Sep 21 '22 08:09

Archimedes Trajano