从android客户端连接到python服务器相同的局域网

时间:2019-06-22 13:46:40

标签: java android python

我正在尝试从android应用程序(在同一LAN上)连接到python服务器,它在以下行失败:

android(客户端):

try {
        Socket s = new Socket("192.168.1.9", 5402);//<--- time out error
    } catch (Exception e) {
        e.printStackTrace();
    }

服务器(在我的计算机上):

import socket  # Import socket module
soc = socket.socket()         # Create a socket object
host = "127.0.0.1" # Get local machine name
port = 5402                # Reserve a port for your service.
soc.bind((host, port))       # Bind to the port
soc.listen(1)                 # Now wait for client connection.
while True:
  conn, addr = soc.accept()     # Establish connection with client.
  print ("Got connection from",addr)
  msg = conn.recv(1024)
  print (msg)

我收到超时错误。我成功连接到用Java编写的Java。有任何想法吗?

0 个答案:

没有答案