服务端
import socket
from multiprocessing import Process
def task(c):
print('顾客吃点啥')
while True:
data = c.recv(1024)
c.send(data.upper())
if __name__ == '__main__':
s = socket.socket()
s.bind(('127.0.0.1', 16666))
s.listen()
while True:
c, addr = s.accept()
print('来了一位顾客 里面请。。。')
p = Process(target=task,args=(c,))
p.start()
客户端
import socket
c = socket.socket()
c.connect(('127.0.0.1',16666))
while True:
msg = input('>>>>')
if not msg:continue
c.send(msg.encode('utf-8'))
data = c.recv(1024)
print(data.decode('utf-8'))