The server fails to send a message to the client java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING]

The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method的问题在于:

The two methods of handlerA and handlerB may be executed at the same time. When A or B method traverses a certain session and calls sendMessage to send a message, the other method is also using the same session to send another message (the same session message is sent Conflict, that is to say, at the same time, multiple threads write data conflicts to a socket), and a TEXT_FULL_WRITING exception will be reported.

The generally adopted solutions are:

Use synchronous lock plus synchronous sending (session.getBasicRemote()), but asynchronous sending is often required.

 

In my project, using Tomcat, TEXT_FULL_WRITING will directly cause the websocket connection to be broken. Using this solution can ensure that a session will only send one message at the same time, so the TEXT_FULL_WRITING error is avoided.

This solution only uses a buffer and lazy judgment method, and is not a standard solution. If you think there is any problem with this solution, or there is a better solution, you can discuss it.
 

Guess you like

Origin blog.csdn.net/wufaqidong1/article/details/129857812