Java Android-Socket客户端通信在Emulator上工作,但在使用VPN的手机上发生“IOException”。
Socket客户端通信在Emulator上工作,但通过使用VPN连接到Windows 7 PC上运行的Socket服务器,手机上会发生“IOException” VPN网络已在手机中成功建立,甚至手机中安装的一些“PING”工具也会对运行Socket Server程序的PC IP进行PING android代码中出现此错误的部分如下所示Java Android-Socket客户端通信在Emulator上工作,但在使用VPN的手机上发生“IOException”。,java,android,sockets,Java,Android,Sockets,Socket客户端通信在Emulator上工作,但通过使用VPN连接到Windows 7 PC上运行的Socket服务器,手机上会发生“IOException” VPN网络已在手机中成功建立,甚至手机中安装的一些“PING”工具也会对运行Socket Server程序的PC IP进行PING android代码中出现此错误的部分如下所示 class CreateSocketClientThread implements Runnable { @Override public vo
class CreateSocketClientThread implements Runnable {
@Override
public void run() {
try {
InetAddress server_addr = InetAddress.getByName("10.51.100.100");
socket = new Socket();
InetSocketAddress inetsocketaddress = new InetSocketAddress(server_addr, 9900);
socket.connect(inetsocketaddress, 5000);
Log.d("debug", "Connected to Socket Server '" + socket.getInetAddress().getHostName() + " : " + socket.getPort() + "'");
updateConversationHandler.post(new updateUIThread1("Connection Established !"));
} catch (UnknownHostException e1) {
Log.d("debug", "unknown host: " + e1.getMessage());
updateConversationHandler.post(new updateUIThread1("Unknown Host error !"));
//e1.printStackTrace();
} catch (IOException e1) {
Log.d("debug", "I/O error: " + e1.getMessage());
updateConversationHandler.post(new updateUIThread1("I/O error !"));
//e1.printStackTrace();
} catch (Exception e1) {
Log.d("debug", "Exception error: " + e1.getMessage());
updateConversationHandler.post(new updateUIThread1("Exception error !"));
//e.printStackTrace();
}
}
}
我还启用了internet权限
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
哪一个例外?您应该发布日志“android代码中出现此错误的部分”。你应该准确地说出哪个语句。04-17 15:42:54.070 4948-4948/com.nmithun.socketcommclient D/mithun﹕ Fn:openSocketConnection 04-17 15:42:59.090 4948-5037/com.nmithun.socketcommclient D/mithun﹕ I/O错误:在5000ms之后无法连接到/10.55.111.28端口9900。您应该确切地说出哪条语句。我重复一遍。您好,greenapps,错误发生在代码行“socket.connectionNetSocketAddress,5000;”因此,它执行“catch IOException e1”语句。