android - socket timeout while connecting -


i'm trying implement tcp client app on android. when try connect c++ server, socket times out while trying connect server.

my code:

new thread(new clientthread()).start(); try {   printwriter out = new printwriter(new bufferedwriter(     new outputstreamwriter(socket.getoutputstream())), true);   out.println("test message."); } catch (exception e) {   // error1   e.printstacktrace(); }  ...  class clientthread implements runnable {   @override   public void run()   {     try     {       inetaddress serveraddr = inetaddress.getbyname("192.168.1.116");       socket = new socket(serveraddr, 9000);     }     catch (exception e)     {       // error2       e.printstacktrace();     }   } } 

first, error1 occurs (socket null), error2 occurs (connection time out). server working fine, have tested different clients. have "uses-permission" shouldn't problem.

edit: stack @ error2:

05-17 02:26:50.789: w/system.err(26625): java.net.connectexception: failed connect /192.168.1.116 (port 9000): connect failed: etimedout (connection timed out) 05-17 02:26:50.789: w/system.err(26625):    @ libcore.io.iobridge.connect(iobridge.java:114) 05-17 02:26:50.789: w/system.err(26625):    @ java.net.plainsocketimpl.connect(plainsocketimpl.java:192) 05-17 02:26:50.789: w/system.err(26625):    @ java.net.plainsocketimpl.connect(plainsocketimpl.java:172) 05-17 02:26:50.789: w/system.err(26625):    @ java.net.socket.startupsocket(socket.java:566) 05-17 02:26:50.789: w/system.err(26625):    @ java.net.socket.<init>(socket.java:225) 05-17 02:26:50.789: w/system.err(26625):    @ cz.gclient.gardenclient.mainactivity$clientthread.run(mainactivity.java:153) 05-17 02:26:50.789: w/system.err(26625):    @ java.lang.thread.run(thread.java:841) 05-17 02:26:50.789: w/system.err(26625): caused by: libcore.io.errnoexception: connect failed: etimedout (connection timed out) 05-17 02:26:50.789: w/system.err(26625):    @ libcore.io.posix.connect(native method) 05-17 02:26:50.789: w/system.err(26625):    @ libcore.io.blockguardos.connect(blockguardos.java:85) 05-17 02:26:50.789: w/system.err(26625):    @ libcore.io.iobridge.connecterrno(iobridge.java:127) 05-17 02:26:50.789: w/system.err(26625):    @ libcore.io.iobridge.connect(iobridge.java:112) 05-17 02:26:50.789: w/system.err(26625):    ... 6 more 

'connection time out' network connectivity problem. there may firewall in way example. isn't programming problem , can't solve in code.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -