def post_listener(sock): while True: ready_to_read, ready_to_write, in_error = \ select.select([sock], [], []) for s in ready_to_read: try: username, msg = message.recieve_msg(s) print("\r" + username + ": " + msg, end="\n") except: print("\rConnection with server was lost") raise Exception return
def serve_chat(): with socketcontext(socket.AF_INET, socket.SOCK_STREAM) as server: server.bind((HOST, PORT)) server.listen(10) connected_sockets.append(server) while True: ready_to_read, ready_to_write, in_error = \ select.select(connected_sockets, [], []) for s in ready_to_read: if s is server: accept_connection(s) else: try: msg = message.recieve_msg(s) message_queue.put(msg) logging.info("Msg recieved from: " + msg[0]) except: connected_sockets.remove(s) logging.info("Disconnected from: " + str(s)) broadcast_messages(server)