我有一个在 NodeJS 中运行的 Socket 服务器。我已从控制台应用程序连接到此库:
https://github.com/Gottox/socket.io-java-client
我使用了示例应用程序(来自链接)并且它工作正常。然后,我将该代码转换为 Android 应用程序,但它没有连接到服务器。我将应用程序的网络权限放在“androidmanifest”文件中,但它也不起作用。
运行应用程序时出现以下错误。预先感谢您的帮助...
02-04 00:56:51.717: D/dalvikvm(971): Late-enabling CheckJNI
02-04 00:56:51.749: D/dalvikvm(971): Debugger has detached; object registry had 1 entries
02-04 00:56:51.761: E/Trace(971): error opening trace file: No such file or directory (2)
02-04 00:56:51.837: W/dalvikvm(971): Unable to resolve superclass of Lio/socket/WebsocketTransport; (851)
02-04 00:56:51.837: W/dalvikvm(971): Link of class 'Lio/socket/WebsocketTransport;' failed
02-04 00:56:51.837: I/dalvikvm(971): Could not find method io.socket.WebsocketTransport.create, referenced from method io.socket.IOConnection.connectTransport
02-04 00:56:51.837: W/dalvikvm(971): VFY: unable to resolve static method 5178: Lio/socket/WebsocketTransport;.create (Ljava/net/URL;Lio/socket/IOConnection;)Lio/socket/IOTransport;
02-04 00:56:51.837: D/dalvikvm(971): VFY: replacing opcode 0x71 at 0x001a
02-04 00:56:51.901: I/System.out(971): an Error occured
02-04 00:56:51.901: W/System.err(971): io.socket.SocketIOException: Error while handshaking
02-04 00:56:51.901: W/System.err(971): at io.socket.IOConnection.handshake(IOConnection.java:322)
02-04 00:56:51.901: W/System.err(971): at io.socket.IOConnection.access$7(IOConnection.java:292)
02-04 00:56:51.901: W/System.err(971): at io.socket.IOConnection$ConnectThread.run(IOConnection.java:199)
02-04 00:56:51.901: W/System.err(971): Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 3000) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
02-04 00:56:51.905: W/System.err(971): at libcore.io.IoBridge.isConnected(IoBridge.java:224)
02-04 00:56:51.905: W/System.err(971): at libcore.io.IoBridge.connectErrno(IoBridge.java:161)
02-04 00:56:51.905: W/System.err(971): at libcore.io.IoBridge.connect(IoBridge.java:112)
02-04 00:56:51.905: W/System.err(971): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
02-04 00:56:51.905: W/System.err(971): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
02-04 00:56:51.905: W/System.err(971): at java.net.Socket.connect(Socket.java:842)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
02-04 00:56:51.905: W/System.err(971): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
02-04 00:56:51.905: W/System.err(971): at io.socket.IOConnection.handshake(IOConnection.java:313)
02-04 00:56:51.909: W/System.err(971): ... 2 more
02-04 00:56:51.909: W/System.err(971): Caused by: libcore.io.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
02-04 00:56:51.909: W/System.err(971): at libcore.io.IoBridge.isConnected(IoBridge.java:208)
02-04 00:56:51.909: W/System.err(971): ... 19 more
02-04 00:56:51.909: I/io.socket(971): Cleanup
02-04 00:56:51.969: D/libEGL(971): loaded /system/lib/egl/libEGL_emulation.so
02-04 00:56:52.021: D/(971): HostConnection::get() New Host Connection established 0xb8a83f48, tid 971
02-04 00:56:52.025: D/libEGL(971): loaded /system/lib/egl/libGLESv1_CM_emulation.so
02-04 00:56:52.029: D/libEGL(971): loaded /system/lib/egl/libGLESv2_emulation.so
02-04 00:56:52.101: W/EGL_emulation(971): eglSurfaceAttrib not implemented
02-04 00:56:52.121: D/OpenGLRenderer(971): Enabling debug mode 0
02-04 00:56:52.181: D/OpenGLRenderer(971): TextureCache::get: create texture(0xb8a3c8e8): name, size, mSize = 1, 1048576, 1048576
02-04 00:56:52.557: D/OpenGLRenderer(971): TextureCache::get: create texture(0xb8a53d18): name, size, mSize = 2, 5184, 1053760
02-04 00:56:52.653: D/OpenGLRenderer(971): TextureCache::get: create texture(0xb8a3a470): name, size, mSize = 4, 20736, 1074496
02-04 00:56:52.665: D/OpenGLRenderer(971): TextureCache::get: create texture(0xb8a37848): name, size, mSize = 6, 2304, 1076800
我是一名优秀的程序员,十分优秀!