环境
andorid studio
io.socket:socket.io-client:2.0.0
代码
1 socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() { 2 @Override 3 public void call(Object... args) { 4 LogUtils.d("connect_error : "+args[0]); 5 } 6 });
问题表现
1.无法连接到socket server
2.用filddler抓包发现请求正常,服务器有响应
3.加了 Socket.EVENT_CONNECT_ERROR 之后捕获到:io.socket.engineio.client.EngineIOException: server error,parser error
根本原因
版本不一致
引用的 io.socket:socket.io-client:2.0.0 使用的socket.IO Server 核心是3.x版本的,而现有的 socket.IO Server (用node.js搭建)使用的核心是2.x 的
参考
https://github.com/socketio/engine.io-client-java
https://socket.io/docs/v3/migrating-from-2-x-to-3-0/
Socket.EVENT_CONNECT_ERROR