转自:http://blog.csdn.net/powerccna/article/details/7760059
python socket bind 可以指定IP, 但如果socket.bind(("192.168.22.112",8099)), 这样的话,127.0.0.1:8099, 或者localhost:8099都无法访问,
bash-3.2# telnet 127.0.0.1 8099
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
bind 0.0.0.0就可以绑定这机器上的所有IP
- s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
- s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- s.bind(("0.0.0.0",8099))
- s.listen(5)
bash-3.2# telnet 127.0.0.1 8099
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
^P^Z