Android:始终连接失败:重新连接时ETIMEDOUT(连接超时)

时间:2014-12-19 04:42:30

标签: android multithreading sockets service

所以,我开始使用socket的单独线程。当用户按下主页按钮时,我将关闭套接字并中断线程一切正常。但是,在中断线程和中断的旧线程用户打开我的应用程序后,我将立即开始启动新线程并执行连接套接字我得到以下错误:

    java.net.ConnectException: failed to connect to /12.111.102.100 (port 3001): W/System.err(21440): java.net.ConnectException: failed to connect to /12.111.102.100 (port 3001): connect failed: ETIMEDOUT (Connection timed out)
    at libcore.io.IoBridge.connect(IoBridge.java:124)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
    at java.net.Socket.connect(Socket.java:882)
    at java.net.Socket.connect(Socket.java:825)
    at com.stm.classlife.services.SocketThread.run(SocketThread.java:47)
    Caused by: android.system.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
    at libcore.io.Posix.connect(Native Method)
    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
    at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
    at libcore.io.IoBridge.connect(IoBridge.java:122)
    ... 5 more

    at libcore.io.IoBridge.connect(IoBridge.java:124)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
    at java.net.Socket.connect(Socket.java:882)
    at java.net.Socket.connect(Socket.java:825)
    at com.stm.classlife.services.SocketThread.run(SocketThread.java:47)
    Caused by: android.system.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
    at libcore.io.Posix.connect(Native Method)
    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
    at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
    at libcore.io.IoBridge.connect(IoBridge.java:122)
    ... 5 more

我不明白为什么会出现连接错误,有人知道如何解决这个问题吗?

提前致谢!

0 个答案:

没有答案