NetEase/pomelo-androidclient

connection is terminated

Opened this issue · 5 comments

h69 commented

org.netease.pomelo: connection is terminated.
org.netease.pomelo: there is no listeners.
System.err: io.socket.SocketIOException: Error while handshaking
System.err: at io.socket.IOConnection.handshake(IOConnection.java:322)
System.err: at io.socket.IOConnection.access$600(IOConnection.java:39)
System.err: at io.socket.IOConnection$ConnectThread.run(IOConnection.java:199)
System.err: Caused by: java.io.FileNotFoundException: http://10.0.2.2:3014/socket.io/1/
System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
System.err: at io.socket.IOConnection.handshake(IOConnection.java:313)

我们项目的核心代码直接用了pomelo-androidchat demo的核心代码,在测试的时候,提示连接错误,求解?

Same problem

h69 commented

已解决。等有时间把解决方案提交上来。

Jul 03, 2017 8:14:55 PM com.netease.pomelo.PomeloClient$1 onError
INFO: connection is terminated.
Jul 03, 2017 8:14:55 PM com.netease.pomelo.PomeloClient emit
WARNING: there is no listeners.
io.socket.SocketIOException: Error while handshaking
at io.socket.IOConnection.handshake(IOConnection.java:322)
at io.socket.IOConnection.access$600(IOConnection.java:39)
at io.socket.IOConnection$ConnectThread.run(IOConnection.java:199)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: http://192.168.10.138:3010/socket.io/1/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1876)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at io.socket.IOConnection.handshake(IOConnection.java:313)
... 2 more
Jul 03, 2017 8:14:55 PM io.socket.IOConnection cleanup
INFO: Cleanup

I found the problem and solved it.
the version of socketio which is used in this version of pomelo client is too old.
you better use the new version which is working fine.
this is the link of github repo:
https://github.com/socketio/socket.io-client-java

h69 commented

我现在把解决方案提交上来~

由于目前网易对android的维护并不积极,所以需要改动的地方也挺多的。
根本原因在于,提供的底层库socketio.jar太老了,已经不能用了。

故需要将底层库更换为比较新的socketio.jar,此外,需要改动网易提供的在android端的源码,因为不能直接替换新的socketio.jar就直接使用,需要对网易提供的库进行api的更新。

我使用的是下面这个版本,
compile 'io.socket:socket.io-client:0.8.3'

并且,对PomeloClient源代码进行修改,

/**
 * Initialize pomelo client.
 * 
 */
public void init() {
       
       socket.connect();
       
       socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
           
           @Override
           public void call(final Object... args) {
               logger.info("connection is connected.");
           }
       });
       
       socket.on(Socket.EVENT_CONNECT_TIMEOUT, new Emitter.Listener() {
          
           @Override
           public void call(Object... args) {
               logger.info("connection is timeout.");
               emit("connect_timeout", null);
           }
       });

       socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
          
           @Override
           public void call(Object... args) {
               logger.info("connection is error.");
         emit("connect_error", null);
           }
       });

       socket.on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {

           @Override
           public void call(Object... args) {
               logger.info("connection is disconnected");
               emit("connect_disconnect", null);
               socket = null;
           }
       });
       
       socket.on(Socket.EVENT_MESSAGE, new Emitter.Listener() {
           
           @Override
           public void call(Object... args) {
               logger.info("response: " + args[0].toString());
               if (args[0].toString().indexOf(JSONARRAY_FLAG) == 0) {
                   processMessageBatch(args[0].toString());
               } else {
                   processMessage(args[0].toString());
               }
           }
       });
       
}

通过以上调整即可解决您的紧急问题。