I am trying to implement a SCTP and asyncio based client using pysctp
sockets. Ideally, I would like to do something like:
async def sctp_client():
sock = sctp.sctpsocket_udp(socket.AF_INET)
reader, writer = await asyncio.open_connection(sock=sock)
writer.write(b'some data', ppid=5)
await writer.drain()
data = await reader.read(100)
print(f'Received: {data.decode()}')
writer.close()
await writer.wait_closed()
In practice, there are two question:
- Is there a way to pass a "transport factory" to
open_connection
or toloop.create_connection
? I want the transport object contained by the streams to usesctp_recv
instead ofrecv
andsctp_send
instead ofsend
. Clearly the easiest way is to derive from the original transport class, but I couldn't find a good pythonic way to do it. - Is there a way to get a custom
StreamWriter
fromopen_connection
? Obviously I could create my own one from the original, add a method to the original or just access the internal transport but these options are awfully ugly. The second best way I can think about is just to implement my ownopen_connection
using theloop.create_connection
.
Thanks a lot!
from Changing transport's recv and send methods
No comments:
Post a Comment