2018-05-10 15:22:19 +03:00
|
|
|
import struct
|
|
|
|
|
|
|
|
from .tcpfull import ConnectionTcpFull
|
|
|
|
|
|
|
|
|
|
|
|
class ConnectionTcpIntermediate(ConnectionTcpFull):
|
|
|
|
"""
|
|
|
|
Intermediate mode between `ConnectionTcpFull` and `ConnectionTcpAbridged`.
|
|
|
|
Always sends 4 extra bytes for the packet length.
|
|
|
|
"""
|
2018-06-14 18:09:20 +03:00
|
|
|
async def connect(self, ip, port):
|
|
|
|
result = await super().connect(ip, port)
|
|
|
|
await self.conn.write(b'\xee\xee\xee\xee')
|
2018-05-10 15:22:19 +03:00
|
|
|
return result
|
|
|
|
|
2018-06-14 18:09:20 +03:00
|
|
|
async def recv(self):
|
|
|
|
return await self.read(struct.unpack('<i', await self.read(4))[0])
|
2018-05-10 15:22:19 +03:00
|
|
|
|
2018-06-14 18:09:20 +03:00
|
|
|
async def send(self, message):
|
|
|
|
await self.write(struct.pack('<i', len(message)) + message)
|