一对多聊天,不用ip,port来判断和谁聊天
1 import socket 2 friend_lst = {'alex':'32','太白':'33'} 3 sk =socket.socket(type=socket.SOCK_DGRAM) 4 sk.bind(('127.0.0.1',9001)) 5 while True: 6 msg,addr = sk.recvfrom(1500) 7 msg = msg.decode('utf-8') 8 name,message = msg.split('|',1) # 只切一次 9 print('