Add timeout parameter on TcpClient.connect() too

This commit is contained in:
Lonami Exo 2017-06-22 19:21:33 +02:00
parent e4fbd87c75
commit 843c16215c
2 changed files with 7 additions and 3 deletions

View File

@ -30,9 +30,12 @@ class TcpClient:
else: # tuple, list, etc.
self._socket.set_proxy(*self._proxy)
def connect(self, ip, port):
"""Connects to the specified IP and port number"""
def connect(self, ip, port, timeout):
"""Connects to the specified IP and port number.
'timeout' must be given in seconds
"""
if not self.connected:
self._socket.settimeout(timeout)
self._socket.connect((ip, port))
self._socket.setblocking(False)
self.connected = True

View File

@ -18,7 +18,8 @@ class TcpTransport:
def connect(self):
"""Connects to the specified IP address and port"""
self.send_counter = 0
self.tcp_client.connect(self.ip, self.port)
self.tcp_client.connect(self.ip, self.port,
timeout=round(self.timeout.seconds))
def is_connected(self):
return self.tcp_client.connected