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

前端 未结 2 1071
天涯浪人
天涯浪人 2021-02-14 02:40

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

2条回答
  •  渐次进展
    2021-02-14 03:22

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

    See WebSocket spec chaper 2.1.3:

    The API limits the registration of MessageHandlers per Session to be one MessageHandler per native websocket message type. [WSC 2.1.3-1] In other words, the developer can only register at most one Mes- sageHandler for incoming text messages, one MessageHandler for incoming binary messages, and one MessageHandler for incoming pong messages. The websocket implementation must generate an error if this restriction is violated [WSC 2.1.3-2].

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

提交回复
热议问题