Add initiative connections to connection set.

This commit is contained in:
Yuxin Wang 2018-10-01 00:14:16 -04:00
parent 9bd517fd4f
commit 590e9cd93f

View file

@ -68,6 +68,8 @@ class MessageServer:
logger.info('Connecting to {}'.format((ip, port)))
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((ip, port))
with self._connections_lock:
self._connections.add(client)
threading.Thread(target=self._read_message, args=(client,)).start()
logger.info('Successfully connected to {} on {}'.format((ip, port), client.getsockname()))
return client