无法连接到android中的套接字超时

时间:2014-10-05 21:19:51

标签: android sockets android-networking

您好,我想连接到本地网络上的服务器,我使用套接字。我在Asyntask doinBackground中进行套接字连接。但我正在赶时间。请参阅以下代码。

@Override
    protected Integer doInBackground(String... arg0) {
        // TODO Auto-generated method stub
        try {
            mSocket = new Socket(arg0[0], Integer.valueOf(arg0[1]));
            return 1;
        } catch ( IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return -1;
    }

以下是捕获的日志:

10-03 18:24:39.025: W/System.err(15775): java.net.ConnectException: failed to connect to         
/192.168.11.125 (port 50000): connect failed: ETIMEDOUT (Connection timed out)
10-03 18:24:39.026: W/System.err(15775):    at libcore.io.IoBridge.connect(IoBridge.java:114)
10-03 18:24:39.028: W/System.err(15775):    at    
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
10-03 18:24:39.029: W/System.err(15775):    at    
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
10-03 18:24:39.031: W/System.err(15775):    at java.net.Socket.startupSocket(Socket.java:566)
10-03 18:24:39.033: W/System.err(15775):    at java.net.Socket.tryAllAddresses(Socket.java:128)
10-03 18:24:39.034: W/System.err(15775):    at java.net.Socket.<init>(Socket.java:178)
10-03 18:24:39.036: W/System.err(15775):    at java.net.Socket.<init>(Socket.java:150)
10-03 18:24:39.037: W/System.err(15775):    at   
com.SDI.hrsimulator.MainActivity$SocketHelper.doInBackground(MainActivity.java:273)
10-03 18:24:39.039: W/System.err(15775):    at 
com.SDI.hrsimulator.MainActivity$SocketHelper.doInBackground(MainActivity.java:1)
10-03 18:24:39.040: W/System.err(15775):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
10-03 18:24:39.041: W/System.err(15775):    at 
java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-03 18:24:39.043: W/System.err(15775):    at 
android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
10-03 18:24:39.044: W/System.err(15775):    at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-03 18:24:39.046: W/System.err(15775):    at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-03 18:24:39.047: W/System.err(15775):    at java.lang.Thread.run(Thread.java:841)
10-03 18:24:39.049: W/System.err(15775): Caused by: libcore.io.ErrnoException: connect failed: 
ETIMEDOUT (Connection timed out)
10-03 18:24:39.053: W/System.err(15775):    at libcore.io.Posix.connect(Native Method)
10-03 18:24:39.054: W/System.err(15775):    at    
libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
10-03 18:24:39.055: W/System.err(15775):    at   
libcore.io.IoBridge.connectErrno(IoBridge.java:127)
10-03 18:24:39.056: W/System.err(15775):    at libcore.io.IoBridge.connect(IoBridge.java:112)
10-03 18:24:39.057: W/System.err(15775):    ... 14 more

arg [0] = ip address =“192.168.11.25”arg [1] =端口号50000

0 个答案:

没有答案