libGDX:android的SocketTimeoutException

时间:2015-06-01 13:24:44

标签: java android sockets libgdx cross-platform

我目前正在使用libgdx。我想通过websockets连接到已经运行的Java Server应用程序。 当我启动桌面应用程序时,Everythins工作正常,但Android应用程序无法连接。

我收到以下LogCat输出:

  

03-13 16:05:21.508:E / AndroidRuntime(27405):致命异常:GLThread 2370   03-13 16:05:21.508:E / AndroidRuntime(27405):进程:com.myProject.android,PID:27405   03-13 16:05:21.508:E / AndroidRuntime(27405):com.badlogic.gdx.utils.GdxRuntimeException:发生与192.168.1.100:4444的套接字连接时出错   03-13 16:05:21.508:E / AndroidRuntime(27405):at com.badlogic.gdx.net.NetJavaSocketImpl。(NetJavaSocketImpl.java:51)   03-13 16:05:21.508:E / AndroidRuntime(27405):at com.badlogic.gdx.backends.android.AndroidNet.newClientSocket(AndroidNet.java:70)   03-13 16:05:21.508:E / AndroidRuntime(27405):at com.myProject.ServerConnector.connect(ServerConnector.java:53)   03-13 16:05:21.508:E / AndroidRuntime(27405):at com.myProject.application.XDKVisualizer.create(XDKVisualizer.java:61)   03-13 16:05:21.508:E / AndroidRuntime(27405):at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)   03-13 16:05:21.508:E / AndroidRuntime(27405):在android.opengl.GLSurfaceView $ GLThread.guardedRun(GLSurfaceView.java:1512)   03-13 16:05:21.508:E / AndroidRuntime(27405):在android.opengl.GLSurfaceView $ GLThread.run(GLSurfaceView.java:1240)   03-13 16:05:21.508:E / AndroidRuntime(27405):引起:java.net.SocketTimeoutException:2147483647ms后无法连接到/192.168.1.100(端口4444):isConnected失败:ETIMEDOUT(连接超时)   03-13 16:05:21.508:E / AndroidRuntime(27405):at libcore.io.IoBridge.isConnected(IoBridge.java:225)   03-13 16:05:21.508:E / AndroidRuntime(27405):at libcore.io.IoBridge.connectErrno(IoBridge.java:165)   03-13 16:05:21.508:E / AndroidRuntime(27405):at libcore.io.IoBridge.connect(IoBridge.java:116)   03-13 16:05:21.508:E / AndroidRuntime(27405):at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)   03-13 16:05:21.508:E / AndroidRuntime(27405):at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:460)   03-13 16:05:21.508:E / AndroidRuntime(27405):at java.net.Socket.connect(Socket.java:838)   03-13 16:05:21.508:E / AndroidRuntime(27405):at com.badlogic.gdx.net.NetJavaSocketImpl。(NetJavaSocketImpl.java:46)   03-13 16:05:21.508:E / AndroidRuntime(27405):...还有6个   03-13 16:05:21.508:E / AndroidRuntime(27405):引起:libcore.io.ErrnoException:isConnected失败:ETIMEDOUT(连接超时)   03-13 16:05:21.508:E / AndroidRuntime(27405):at libcore.io.IoBridge.isConnected(IoBridge.java:212)   03-13 16:05:21.508:E / AndroidRuntime(27405):... 12 more

以下是服务器和客户端应用程序的代码段: 服务器:

ServerSocket serverSocket = new ServerSocket(mPort);
    try {
        while (listening) {
            Socket clientSocket = serverSocket.accept();
            Thread sender = new SensorDataSender(clientSocket, numClients++);
            sender.start();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        serverSocket.close();
    }

客户端:

    SocketHints hints = new SocketHints();
    hints.connectTimeout = CONNECTION_TIMEOUT;
    hints.socketTimeout = SOCKET_TIMEOUT;
    Socket socket = Gdx.net
            .newClientSocket(Protocol.TCP, mIp, mPort, hints);

    BufferedReader in = new BufferedReader(new InputStreamReader(
                socket.getInputStream()));

    new EventProcessor(in).start();

为什么这不起作用的任何想法?我已经尝试了kyronet替代方案并收到了同样的超时。

BR, Flo

0 个答案:

没有答案