1、服务器与多客户端通信
1 import socket 2 # 创建tcp socket的套接字 3 sk = socket.socket() 4 # bind 5 sk.bind((‘127.0.0.1‘,8080)) 6 # 监听 7 sk.listen(5) 8 # 等待连接 9 while 1: 10 conn, addr = sk.accept() 11 while 1: 12 msg_s = input(‘>>>‘) 13 conn.send(msg_s.encode(‘utf-8‘)) 14 if msg_s == ‘q‘: 15 break 16 msg_r = conn.recv(1024).decode(‘utf-8‘) 17 if msg_r == ‘q‘: 18 break 19 print(msg_r) 20 conn.close() 21 22 sk.close()
TCP_服务器端
1 import socket 2 3 sk = socket.socket() 4 5 sk.connect((‘127.0.0.1‘,8080)) 6 7 8 while 1: 9 msg_r = sk.recv(1024).decode(‘utf-8‘) 10 if msg_r == ‘q‘: 11 break 12 print(msg_r) 13 msg_s = input(‘>>>‘) 14 sk.send(msg_s.encode(‘utf-8‘)) 15 if msg_s == ‘q‘: 16 break 17 18 sk.close()
TCP_客户端
2、UDP协议
3、pycharm打印带颜色输出
4、时间同步的机制
原文地址:https://www.cnblogs.com/ZN-225/p/9142178.html
时间: 2024-10-10 00:01:59