开发者

Android Sockets programing, accept doesn't accept LAN connections

I am implementing a SocketServer for an Android device.

The device I am using is Samsung G2 I9100.
1. The device is connected to LAN through WiFi
2. The IP returned to the device using 'NetworkInterface.getNetworkInterfaces()' & friends is 192.168.2.9
3. The server implementation is as follows:
   java.net.Socket socClient; 
   m_socServer = new java.net.ServerSocket(5050);
   m_socServer.setSoTimeout(0);
   socClient = m_socServer.accept();
4. Connection is accepted When using a local thread to connect eiather to 127.0.0.1:5050 or to192.168.2.9:5050
5. when trying to connect using eg. telnet @ Win7 'm_socServer.accept()' keeps on blocking and the connection timesout on the Win7 telnet session.
6. I have set the 开发者_Go百科'android.permission.INTERNET' permission.

Why does inproc connection attempts succeed while LAN connection attentps fail? 

Any help will be appreciated.

~Nadav


Several things to check:

1) That you can ping the android device from your win7 box - ie, they are on the same wifi network and it's willing to route packets. ping 192.168.2.9 should work.

2) That you are using a form of the telnet command on windows with is accepting the custom port 5050 instead of the standard one. telnet 192.168.2.9 5050 should work, but you might try grabbing a copy of netcat or putty to use instead of telnet if there's any doubt.

3) That traffic is actually being generated - run a tcpdump-like tool on either the win7 box or if available (or you have root and can add it) the phone and see that there are connection attempts being made to the 5050 port.

4) Normally I would also suggest that you use netstat -n on the phone to verify that you are listening on port 5050 - your in-program tests seems to have done that but it wouldn't hurt to be sure. You can also see if netcat is installed on the phone (as 'nc') and use that from the adb command line for a local connection attempt that's not your program testing itself, but that shouldn't really matter.

5) You could also try a different port

6) Make sure there's no firewall on the win7 box blocking outbound traffic

7) Make sure there's no firewall or subnet separation on the wifi router blocking traffic between clients on the port you are using, or between the wired ethernet ports (if that's where the win7 box is) and the wifi clients. It's slightly suspicious that your phone's ip address is 192.168.2.x - this could imply that your wifi is being run as a separate subnet from your wired Ethernet.

8) Try your program on the emulator using an adb port forward

9) Try somebody else's program that does something similar on the phone, perhaps an ssh server or web server, willing to run on an unprivileged higher port in order to not require root.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜