#server.py
import struct
import socket
import socketserver
from multiprocessing import Process
import time
def accept(conn):
while True:
time.sleep(1)
data = conn.recv(4).decode('utf-8')
msg = data.encode('utf-8')
conn.send(msg)
if __name__ == '__main__':
server = socket.socket()
server.bind((
'127.0.0.1', 8002
))
server.listen(3)
while True:
conn, addr = server.accept()
print(addr)
p = Process(target=accept, args=(conn,))
p.start()
#client.py
import socket
import struct
client = socket.socket()
client.connect((
'127.0.0.1', 8002
))
while True:
msg = input('客户端:')
msg = msg.encode('utf-8')
client.send(msg)
data = client.recv(1024).decode('utf-8')
print(data)