websocket接受消息后报An exceptionCaught() event was fired, and it reached at the tail of the pipeline.

卤煮今天在解决完跨域问题之后,用另一个ip像服务器发数据,能正常收到数据,但是又出现了新的错误。
在做websocket连接之后,前端发送消息,收到之后,会报以下错误:
客户端收到服务器数据:787878877878

2019-05-18 11:37:46.015 WARN 11188 — [ntLoopGroup-4-1] io.netty.channel.DefaultChannelPipeline :
An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.大概就说是管道最后出现了个什么异常,handler中没有处理这个异常的方法。
net.sf.json.JSONException: A JSONObject text must begin with ‘{’ at character 1 of 787878877878
at net.sf.json.util.JSONTokener.syntaxError(JSONTokener.java:499) ~[json-lib-2.4.jar:na]
at net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:972) ~[json-lib-2.4.jar:na]
at net.sf.json.JSONObject._fromString(JSONObject.java:1201) ~[json-lib-2.4.jar:na]
at net.sf.json.JSONObject.fromObject(JSONObject.java:165) ~[json-lib-2.4.jar:na]
at net.sf.json.JSONObject.fromObject(JSONObject.java:134) ~[json-lib-2.4.jar:na]
at com.jys.websocket.handler.JsonUtils.getMap4Json(JsonUtils.java:45) ~[classes/:na]
at com.jys.websocket.handler.WebSocketHandler.handleWebSocketFream(WebSocketHandler.java:43) ~[classes/:na]
at com.jys.websocket.handler.WebSocketHandler.channelRead0(WebSocketHandler.java:114) ~[classes/:na]
at com.jys.websocket.handler.WebSocketHandler.channelRead0(WebSocketHandler.java:19) ~[classes/:na]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) ~[netty-all-4.1.34.Final.jar:4.1.34.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-all-4.1.34.Final.jar:4.1.34.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:345) [netty-all-4.1.34.Final.jar:4.1.34.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:337) [netty-all-4.1.34.Final.jar:4.1.34.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) [netty-l]


解决办法:
我们在自己的SocketHandler 里面
重写一个exceptionCaught 方法

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {

}

重启服务器就行了。
websocket接受消息后报An exceptionCaught() event was fired, and it reached at the tail of the pipeline._第1张图片

你可能感兴趣的:(websocket接受消息后报An exceptionCaught() event was fired, and it reached at the tail of the pipeline.)