Android - 套接字客户端通信适用于模拟器,但是“IOException”#39;使用VPN在手机上发生。

时间:2015-04-16 16:00:47

标签: java android sockets

Socket客户端通信可以在仿真器上运行但是“IOException”#39;通过使用VPN连接到在Windows 7 PC上运行的套接字服务器,在手机上发生。

VPN网络在手机中成功建立,甚至还有一些PING'安装在手机中的工具会ping到正在运行Socket Server程序的PC IP。

看到此错误的android代码部分如下。

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();
        }
    }
}

我也启用了互联网权限

    <uses-permission android:name="android.permission.INTERNET" >
    </uses-permission>

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >

0 个答案:

没有答案