我正在使用 TCP 将我的 android 手机与 Windows 7 PC 连接起来。当我在局域网中发送消息电话-PC 时,此系统正常工作,因为我在 Internet 中使用此系统,她已关闭,因为 android 应用程序向我发送“超时”。为什么?
// The host name can either be a machine name, such as "java.sun.com", or a
// textual representation of its IP address
String host = "10.26.144.118";
int port = 20;
try {
Socket socket = new Socket(InetAddress.getByName(host), port);
BufferedReader reader = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);
// true for auto flush
writer.println("Hello World");
myView.setText("Send hello world");
} catch (Exception e) {
System.out.println("Error" + e);
myView.setText("Error" + e);
}