1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import socket import threading
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('127.0.0.1', 8000))
server.listen()
def handle_sock(sock, addr): while True: data = sock.recv(1024).decode('utf8') if data == 'Q': break print(data) ret_data = input('please input: ') sock.send(ret_data.encode('utf-8')) sock.close()
while True: sock, addr = server.accept() client_sock = threading.Thread(target=handle_sock, args=(sock, addr)) client_sock.start()
|