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 'android.permission.INTERNET' permission.
Why does inproc connection attempts succeed while LAN connection attentps fail?
Any help will be appreciated.
~Nadav发布于 2011-09-04 12:42:14
有几件事需要检查:
1)你可以将安卓设备从你的win7机箱中打开--也就是说,它们在同一个wifi网络上,而且它愿意发送数据包。平192.168.2.9应起作用。
2)在windows上使用telnet命令的形式是接受自定义端口5050,而不是标准端口。telnet 192.168.2.9 5050应该可以工作,但如果有任何疑问,您可以尝试获取netcat或putty的副本,而不是telnet。
3)实际正在生成通信量--在win7框上运行类似tcpdump的工具,或者如果可用(或者您有根并可以添加它),则运行电话,并查看正在尝试连接5050端口。
4)通常,我还建议您在电话中使用netstat -n来验证您正在监听端口5050 --您的程序内测试似乎已经做到了这一点,但是确定一下不会有什么影响。您还可以看到netcat是否安装在电话上(作为“nc”),并将它从亚行命令行中用于本地连接尝试,这不是您的程序测试本身,但这并不重要。
5)您还可以尝试另一个端口
6)确保win7框上没有防火墙阻止出站通信
7)确保在wifi路由器上没有防火墙或子网隔离,阻止您正在使用的端口上的客户端、或有线以太网端口(如果是win7框所在的话)与wifi客户端之间的通信。对您的电话ip地址为192.168有点怀疑。2.x--这可能意味着您的wifi正在作为独立的子网运行,而不是有线以太网。
8)在模拟器上使用adb端口进行程序转发。
9)尝试其他人的程序,这些程序在电话上执行类似的操作,可能是ssh服务器或web服务器,它们愿意在没有特权的更高端口上运行,从而不需要根用户。
https://stackoverflow.com/questions/7298564
复制相似问题