def _attempt_listening(self): self._sync_actions() if self._awaiting_connection is not None: # Cannot handle multiple connection requests at the same time return try: socketutils.wait_for_read([self._listener_sock], timeout=0) except socketutils.TimeoutError: return conn = Bunch() data, conn.remote_address = self._listener_sock.recvfrom(MAX_PACKET_SIZE) remote_hostname, remote_port = conn.remote_address remote_version, conn.remote_host_id, conn.remote_host_name = loads(data) assert remote_version == self.protocol_version, "Attempt to connect with client of different version" if conn.remote_address in self._already_connected: # We may be receiving a retransmit of the connection # packet from before, anyhow, he is already connected, so # ignore it. return self.notify("new_connector1", conn.remote_host_name, conn.remote_address) conn.sock=socketutils.new_udp_socket() conn.sock.connect(conn.remote_address) host_ids = [(host.id, host.name) for host in self.hosts] welcome_to_send = dumps(('WELCOME!', (self._publicized_data, host_ids))) conn._welcome_to_send = welcome_to_send conn._welcome_count = 0 self._awaiting_connection = conn self.update = self._send_welcome