Created
November 15, 2023 22:25
-
-
Save Lord-McSweeney/f7d5bdd9ba6d63e945cd3f55bf32289b to your computer and use it in GitHub Desktop.
compliment to sock.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from socket import socket | |
from threading import Thread | |
kDefault_port = 18056 | |
started_extra = 0 | |
threads = [] | |
server_socket = socket() | |
server_socket.bind(("127.0.0.1", kDefault_port)) | |
server_socket.listen() | |
def wait_accept(level): | |
global started_extra | |
if not started_extra: | |
started_extra += 1 | |
thread = Thread(target=wait_accept, args=(level+1,)) | |
threads.append(thread) | |
thread.start() | |
(connection, (address, _port)) = server_socket.accept() | |
started_extra -= 1 | |
data = connection.recv(128).decode('utf-8') | |
if not data.startswith('HELO DRAWCLIENT'): | |
print("WARN Invalid handshake signature from client (was " + data + "), terminating connection") | |
connection.close() | |
return | |
print("INFO Accepted connection from " + str(address) + ", client version " + data[15:]) | |
connection.send(b'WELCOME') | |
if not started_extra: | |
started_extra += 1 | |
thread = Thread(target=wait_accept, args=(level+1,)) | |
threads.append(thread) | |
thread.start() | |
wait_accept(0) | |
for thread in threads: | |
thread.join() |
need to restart every so often to prevent an error
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
assigns a specific number to each connection?