作者:mobiledu2502926503 | 来源:互联网 | 2023-08-25 13:02
服务端
1 2 3 4 5 6 7 8 9 10 11 12
| # coding:utf-8
# server.py
import socket
sock_server = socket.socket()
sock_server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock_server.bind(("127.0.0.1",1234))
sock_server.listen(3)
print("server start ...")
while True:
tmp = sock_server.accept()
print(tmp,"\n\n") |
客户端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| # coding:utf-8
import socket
def make_socks(sock_num):
socks = []
for i in range(sock_num):
tmp_sock = socket.socket()
tmp_sock.connect(("127.0.0.1",1234))
socks.append(tmp_sock)
return socks
if __name__ == "__main__":
make_socks(5) |
如上例代码中,有listen(3),这个3是指什么,是指,这个socket只能与3个socket建立链接吗,为什么我用上面的代码可以创建大于3个的tcp连接却没报错,理论上大于3个连接应该报错的