diff --git a/telethon/network/mtproto_plain_sender.py b/telethon/network/mtproto_plain_sender.py index 57d7a60e..1fa1fbc1 100755 --- a/telethon/network/mtproto_plain_sender.py +++ b/telethon/network/mtproto_plain_sender.py @@ -12,6 +12,7 @@ class MtProtoPlainSender: self._time_offset = 0 self._last_msg_id = 0 self._transport = transport + self._transport.connect() def send(self, data): """Sends a plain packet (auth_key_id = 0) containing the given message body (data)""" diff --git a/telethon/network/tcp_client.py b/telethon/network/tcp_client.py index 2bc9fc9d..29618cbd 100755 --- a/telethon/network/tcp_client.py +++ b/telethon/network/tcp_client.py @@ -31,13 +31,15 @@ class TcpClient: def connect(self, ip, port): """Connects to the specified IP and port number""" - self.socket.connect((ip, port)) - self.connected = True + if not self.connected: + self.socket.connect((ip, port)) + self.connected = True def close(self): """Closes the connection""" - self.socket.close() - self.connected = False + if self.connected: + self.socket.close() + self.connected = False def write(self, data): """Writes (sends) the specified bytes to the connected peer"""