标签:div server 协议 serve pre 聊天 qq聊天 import encode
#server端 import socket ip_port = (‘127.0.0.1‘,8080) sk = socket.socket() sk.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) sk.bind(ip_port) sk.listen() conn,addr = sk.accept() while True: msg = conn.recv(1024).decode(‘utf-8‘) if msg == ‘bye‘: conn.send(b‘bye‘) break print(msg) info = input(‘>>>‘) conn.send(info.encode(‘utf-8‘)) conn.close() sk.close()
#client端 import socket sk = socket.socket() sk.connect((‘127.0.0.1‘,8080)) while True: msg = input(‘>>>‘) sk.send(bytes(msg,encoding=‘utf-8‘)) ret = sk.recv(1024).decode(‘utf-8‘) if ret == ‘bye‘: break print(ret) sk.close()
标签:div server 协议 serve pre 聊天 qq聊天 import encode
原文地址:https://www.cnblogs.com/kuraki/p/9573905.html