Telethon/telethon/network/connection/tcpintermediate.py
2018-06-14 19:35:12 +02:00

21 lines
624 B
Python

import struct
from .tcpfull import ConnectionTcpFull
class ConnectionTcpIntermediate(ConnectionTcpFull):
"""
Intermediate mode between `ConnectionTcpFull` and `ConnectionTcpAbridged`.
Always sends 4 extra bytes for the packet length.
"""
async def connect(self, ip, port):
result = await super().connect(ip, port)
await self.conn.write(b'\xee\xee\xee\xee')
return result
async def recv(self):
return await self.read(struct.unpack('<i', await self.read(4))[0])
async def send(self, message):
await self.write(struct.pack('<i', len(message)) + message)