import config_loader import socket import log """ https://realpython.com/python-sockets/#multi-connection-client-and-server """ config = config_loader.get_config() class SocketServer: """ groundwork for internet comms """ def __init__(self): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: self.server = s s.bind((config['server']['host'], config['server']['port'])) s.listen() log.debug(f'* Server listening on {config["server"]["port"]}') # find a way to spin up a thread or some coprocessor to deal with this self.connect(s.accept()) def connect(self, connection, addr): with connection: log.debug(f'> Accepted connection from {addr}') while True: data = connection.recv(1024) if not data: break # erm... what # why are we mass pinging? connection.sendall(data)