From 6069188b54f99deee996c263bd4d6db60e2b4e77 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 29 Apr 2017 20:57:08 +0200 Subject: [PATCH] MtProtoPlainSender was not connecting (closes #62) --- telethon/network/mtproto_plain_sender.py | 1 + telethon/network/tcp_client.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) 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"""