标签:pychar end 打印 cep 同步 127.0.0.1 import one list
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()
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()
2、UDP协议
3、pycharm打印带颜色输出
4、时间同步的机制
Python全栈__服务器与多客户端通信、UDP协议、pycharm打印带颜色输出、时间同步的机制
标签:pychar end 打印 cep 同步 127.0.0.1 import one list
原文地址:https://www.cnblogs.com/ZN-225/p/9142178.html