- 多线程模拟qq
from multiprocessing import Process from socket import * def sService(new_socket,socket_ip_port): while True: sData = new_socket.recv(1024) if len(sData) > 0: print("%s发的数据位:%s"%(str(socket_ip_port),sData.decode("gb2312"))) new_socket.send("收到".encode("gb2312")) else: break new_socket.close() def main(): socket_tcp = socket(AF_INET,SOCK_STREAM) port = int(input("请输入port:")) bind_addr = ("",7288) socket_tcp.bind(bind_addr) socket_tcp.listen(5) while True: new_socket,socket_ip_port = socket_tcp.accept() p1 = Process(target=sService,args=(new_socket,socket_ip_port)) p1.start() socket_tcp.close() if __name__ == "__main__": main()
python多线程模仿qq
于 2019-05-04 20:02:24 首次发布