问题描述
我在运行的NodeJS一个套接字服务器。我从一个控制台应用程序连接与此库:
我用(从链接)的示例应用程序,它工作正常。然后,我把这一code到Android应用,但它没有连接到服务器。我把androidmanifest文件中的应用程序的网络权限,但它也不能工作。
贝娄是错误,当我运行应用程序。在此先感谢您的帮助...
02-04 00:56:51.717:D / dalvikvm(971):晚启用CheckJNI
02-04 00:56:51.749:D / dalvikvm(971):调试器分离;对象注册了1项
02-04 00:56:51.761:E /跟踪(971):错误打开跟踪文件:没有这样的文件或目录(2)
02-04 00:56:51.837:W / dalvikvm(971):无法解析廖氏的超/插座/ WebsocketTransport; (851)
02-04 00:56:51.837:W / dalvikvm(971):类链接廖氏/插座/ WebsocketTransport;'失败
02-04 00:56:51.837:I / dalvikvm(971):找不到方法io.socket.WebsocketTransport.create,从方法io.socket.IOConnection.connectTransport引用
02-04 00:56:51.837:W / dalvikvm(971):VFY:无法解析静态方法5178:廖氏/插座/ WebsocketTransport; .create(Ljava / NET / URL;廖氏/插座/ IOConnection;)廖氏/插座/ IOTransport;
02-04 00:56:51.837:D / dalvikvm(971):VFY:在更换运code 0x71 0x001a
02-04 00:56:51.901:我/的System.out(971):时出错
02-04 00:56:51.901:W / System.err的(971):io.socket.SocketIOException:错误时握手
02-04 00:56:51.901:W / System.err的(971):在io.socket.IOConnection.handshake(IOConnection.java:322)
02-04 00:56:51.901:W / System.err的(971):在io.socket.IOConnection.access $ 7(IOConnection.java:292)
02-04 00:56:51.901:W / System.err的(971):在io.socket.IOConnection $ ConnectThread.run(IOConnection.java:199)
02-04 00:56:51.901:W / System.err的(971):java.net.ConnectException:产生的原因无法连接到10000ms后/127.0.0.1(3000端口):isConnected失败:ECONNREFUSED(连接被拒绝)
02-04 00:56:51.905:W / System.err的(971):在libcore.io.IoBridge.isConnected(IoBridge.java:224)
02-04 00:56:51.905:W / System.err的(971):在libcore.io.IoBridge.connectErrno(IoBridge.java:161)
02-04 00:56:51.905:W / System.err的(971):在libcore.io.IoBridge.connect(IoBridge.java:112)
02-04 00:56:51.905:W / System.err的(971):在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
02-04 00:56:51.905:W / System.err的(971):在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
02-04 00:56:51.905:W / System.err的(971):在java.net.Socket.connect(Socket.java:842)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpConnection<&初始化GT;(HttpConnection.java:76)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpConnection<&初始化GT;(HttpConnection.java:50)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpConnection $ Address.connect(HttpConnection.java:341)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
02-04 00:56:51.905:W / System.err的(971):在libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
02-04 00:56:51.905:W / System.err的(971):在io.socket.IOConnection.handshake(IOConnection.java:313)
02-04 00:56:51.909:W / System.err的(971):... 2更多
02-04 00:56:51.909:W / System.err的(971):libcore.io.ErrnoException:产生的原因isConnected失败:ECONNREFUSED(连接被拒绝)
02-04 00:56:51.909:W / System.err的(971):在libcore.io.IoBridge.isConnected(IoBridge.java:208)
02-04 00:56:51.909:W / System.err的(971):19 ...更多
02-04 00:56:51.909:I / io.socket(971):清理
02-04 00:56:51.969:D / libEGL(971):装载/system/lib/egl/libEGL_emulation.so
02-04 00:56:52.021:D /(971):HostConnection ::得到()新主机连接建立0xb8a83f48,TID 971
02-04 00:56:52.025:D / libEGL(971):装载/system/lib/egl/libGLESv1_CM_emulation.so
02-04 00:56:52.029:D / libEGL(971):装载/system/lib/egl/libGLESv2_emulation.so
02-04 00:56:52.101:W / EGL_emulation(971):eglSurfaceAttrib没有实现
02-04 00:56:52.121:D / OpenGLRenderer(971):启用调试模式0
02-04 00:56:52.181:D / OpenGLRenderer(971):TextureCache ::获得:建立纹理(0xb8a3c8e8):名称,大小,MSIZE = 1,1048576,1048576
02-04 00:56:52.557:D / OpenGLRenderer(971):TextureCache ::获得:建立纹理(0xb8a53d18):名称,大小,MSIZE = 2,5184,1053760
02-04 00:56:52.653:D / OpenGLRenderer(971):TextureCache ::获得:建立纹理(0xb8a3a470):名称,大小,MSIZE = 4,20736,1074496
02-04 00:56:52.665:D / OpenGLRenderer(971):TextureCache ::获得:建立纹理(0xb8a37848):名称,大小,MSIZE = 6,2304,1076800
您无法从仿真器连接到本地机器上直接使用本地主机
或 127.0.0.1
- 你必须使用一个特殊的地址
地址连接到您的本地机器上运行的服务器(从仿真器)是 10.0.2.2
的
I got a Socket Server running in NodeJS. I've connected from a Console Application with this library:
https://github.com/Gottox/socket.io-java-client
I used the example app (from the link) and it works correctly. Then, I translate that code to an Android application, but it doesn't connect to the Server. I put the Network Permissions of the app inside the "androidmanifest" file, but it didn't work either.
Bellow is the error when I run the app. Thanks in advance for the help...
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
You can't connect from the emulator to your local machine directly using localhost
or 127.0.0.1
- you have to use a special address.
The address to connect to a server running on your local machine (from the emulator) is 10.0.2.2
, as described in the developer documentation.
这篇关于错误的Android客户端连接到一个的NodeJS socket服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!