Skip to content

Instantly share code, notes, and snippets.

@arseniyturin
Last active December 29, 2021 16:53
Show Gist options
  • Save arseniyturin/829e702cc52a78a6345e15000afab4cb to your computer and use it in GitHub Desktop.
Save arseniyturin/829e702cc52a78a6345e15000afab4cb to your computer and use it in GitHub Desktop.
import socket
from threading import Thread
def server(host='', port=8000):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
sock.bind((host, port))
sock.listen()
while True:
client, address = sock.accept()
Thread(target=handle_client, args=(address, client), daemon=True).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment