ITKeyword,专注技术干货聚合推荐

注册 | 登录

unable to connect to socket in android getting timed out

itPublisher 分享于

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址https://www.aliyun.com/minisite/goods

推荐:Android AVD之Socket Connect Time Out

01-28 02:57:11.545: D/TyLogin(297): calling connect 01-28 02:57:36.253: I/ActivityManager(59): Process android.process.acore (pid 169) has died. 01-28

Hi I want to connect to server on a local network and I using socket for this. I am doing the socket connect part in Asyntask doinBackground. But I am getting timedout. please see the below code.

@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;
    }

Following is the logs captured :

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] = port number 50000

推荐:android socket 本机调试 connection time out 解决办法

调试socket程序的时候,发现client端总是出现connection time out情况。 调试ip为10.0.2.2,本机ip为192.168.1.111。 后来想了下,将服务器ip和手机ip分开来,再

android sockets android-networking
|
  this question
edited Oct 5 '14 at 21:34 asked Oct 5 '14 at 21:19 user954299 85 3 12      You think it is not important that we know the contents of arg0[0] and [1] ? Please post the log in a codeblock too so it does not wrap. –  greenapps Oct 5 '14 at 21:27 1   You could switch off the firewall. –  greenapps Oct 5 '14 at 21:31      @greenapps arg[0] = ip address = "192.168.11.25" arg[1] = port number 50000 I have edited the logs so that its placed in code block. –  user954299 Oct 5 '14 at 21:39

 | 

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

推荐:Android Studio:Gradle project refresh failed. Connection timed out: connect.

事件 换了个电脑,Android Studio拷过来,重新配置后,打开已有的项目,报错: Gradle project refresh failed. Connection timed out: connect. 这是因为Studio


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。