我使用了普思松的袖珍模块,并试图利用听器开张。
import socket
import sys
def getServerSocket(host, port):
for r in socket.getaddrinfo(host, port, socket.AF_UNSPEC,
socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
af, socktype, proto, canonname, sa = r
try:
s = socket.socket(af, socktype, proto)
except socket.error, msg:
s = None
continue
try:
s.bind(sa)
s.listen(1)
except socket.error, msg:
s.close()
s = None
continue
break
if s is None:
print could not open socket
sys.exit(1)
return s
东道国无,港口为15,000。
之后,该方案将接受连接,但只接受同一机器的连接。 我必须做些什么来接受互联网连接?