服务端
# 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,"
")
客户端
# 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个连接应该报错的
TCP握手与socket通信细节
一周热门 更多>