org.java_websocket.exceptions.WebsocketNotConnectedException: null

WebSocketClient连接webSocket服务端发送消息报错,错误信息如下:

 org.java_websocket.exceptions.WebsocketNotConnectedException: null
    at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:630)
    at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:607)
    at org.java_websocket.client.WebSocketClient.send(WebSocketClient.java:344)

 通过查看源码可以发现当前的webSocket连接是not isOpen

org.java_websocket.exceptions.WebsocketNotConnectedException: null_第1张图片

如何解决?

在send之前加一个等待

while (!client.getReadyState().equals(ReadyState.OPEN)) {
        logger.debug("连接中···请稍后");
     }
client.send("hello,webSocket connected");

 

你可能感兴趣的:(java)