java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method 解决办法

java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1015)
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.textStart(WsRemoteEndpointImplBase.java:978)
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendString(WsRemoteEndpointImplBase.java:161)
at org.apache.tomcat.websocket.WsRemoteEndpointBasic.sendText(WsRemoteEndpointBasic.java:37)

Bad:

@OnMessage
public String onMessage(String message, Session session) {
   ...
   return message;
}

Good:

@OnMessage
public void onMessage(String message, Session session) {
   ...
}
再次测试
public  void  handleTextMessage(WebSocketSession session,TextMessage message){
    ...
}
改为
public synchronized void  handleTextMessage(WebSocketSession session,TextMessage message){
    ...
}
或者
String websocketsesssion_id = map_id.get(username);
WebSocketSession wss = map_users.get(websocketsesssion_id);
synchronized(wss) {
 wss.sendMessage(new TextMessage(new java.util.Date()));
}

posted @ 2015-10-10 10:44  锐洋智能  阅读(17926)  评论(0编辑  收藏  举报