python version: 3.7.3
import socket
import threading
class Worker(threading.Thread):
def __init__(self, sock):
threading.Thread.__init__(self)
self.sock = sock
def run(self):
while True:
conn, addr = self.sock.accept()
conn.recv(1024)
print(addr)
conn.send(bytes('HTTP/1.0 200 OK\n\nhi, there!
', encoding='utf8'))
conn.close()
sock = socket.socket()
sock.bind(('127.0.0.1', 1231))
sock.listen(1)
for i in range(3):
w = Worker(sock)
w.start()