import socket import select MAX_CLIENTS = 7 ALLOWED_CLIENTS = [] class world_server: def __init__(self, port=2200): """Prepares a basic server""" self.port = port self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.bind((socket.gethostname(), port)) self.sock.listen(7) def string_listen(self): """Listens through ALLOWED_CLIENTS, and returns messages""" (a1,a2,e1) = select.select(ALLOWED_CLIENTS, ALLOWED_CLIENTS, [], 20) for x in a1: cow = x(0).recv(10) cow = cow.decode() if "" != cow and (x in a2): x(0).send(b'goodbye*') def permit(self): """Allows clients to get on list""" if MAX_CLIENTS >= len(ALLOWED_CLIENTS): "There's no space, client should know" (sfail, address) = self.sock.accept() sfail.send(b'No room here.*') sfail.close() else: (spass, address) = self.sock.accept() ALLOWED_CLIENTS.append((spass, address))