我有这个程序,它现在应该只监听端口 80 并从浏览器连接或另一个 python 脚本接收数据。这段代码:
import socket # Import socket module
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname() # Get local machine name
port = 80 # Reserve a port for your service.
s.bind(("192.168.252.7", port)) # Bind to the port
s.listen(5) # Now wait for client connection.
while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
print c.recv(1024)
c.close() # Close the connection
这都是从tutorialspoint复制的。此代码接收数据,当端口设置为 80 以外的任何值(例如 8080、12345)时,但当它是 80 时,它只接受客户端但似乎没有收到任何数据,尽管数据已从其他地方成功发送.. ..请帮助伙计们