为了能够在H5和APP都保持同一套长连接接口,因为采用websocket协议作为开发
使用的第三方库是:https://github.com/TakahikoKawasaki/nv-websocket-client
一开始在本地开发的时候,就遇到问题了,总是连接不上
WebSocketFactory factory = new WebSocketFactory();
WebSocket ws = factory.createSocket("ws://127.0.0.1:9999");
报的是这个错误
com.neovisionaries.ws.client.WebSocketException: Failed to connect to '127.0.0.1:9999': failed to connect to /127.0.0.1 (port 9999): connect failed: ECONNREFUSED (Connection refused)
试了很久,包括换成localhost,还是一样的错误,后来在这里找到了解决方案
http://*.com/questions/18619195/connection-refused-on-remote-ip-but-accepted-on-local-ip-solved
将127.0.0.1改成内网IP,192.168.0.100,就可以了,莫名奇妙的。
Have fun with Android!