23 lines
630 B
Python
23 lines
630 B
Python
import os
|
|
import socket
|
|
from multiprocessing import Process
|
|
|
|
def handle_client(cli: socket, addr):
|
|
# For now just print out the received bytes and close
|
|
print("Received connection from", addr)
|
|
recv_data = cli.recv(4096)
|
|
print(recv_data.decode("utf-8"))
|
|
cli.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
address = ''
|
|
port = 8080
|
|
so = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
so.bind((address, port))
|
|
so.listen(5)
|
|
while True:
|
|
(client_socket, client_address) = so.accept()
|
|
print("Client connected")
|
|
Process(target=handle_client, args=(client_socket, client_address)).start()
|