标签:connect socket name decode send UNC 进程 tar process
多进程server端实现:
import socket from multiprocessing import Process def func(conn): ‘‘‘ 没调用一次func创建一个新进程 :param conn: :return: ‘‘‘ try: #持续对话 while 1: data = conn.recv(1024) print(data.decode(‘utf-8‘)) conn.send(b‘hello‘) except: print(‘进程结束‘) conn.close() if __name__ == ‘__main__‘: sk = socket.socket() sk.bind((‘127.0.0.1‘, 8555)) sk.listen(5) while 1: #每进行一次连接创建一个进程开启对话 conn,addr = sk.accept() p =Process(target= func,args=(conn,)) p.start()
client端
import socket sk = socket.socket() sk.connect((‘127.0.0.1‘,8555)) while 1: sk.send(b‘nihao‘) data = sk.recv(1024) print(data.decode(‘utf-8‘))
标签:connect socket name decode send UNC 进程 tar process
原文地址:https://www.cnblogs.com/learn-record/p/14366255.html