import asyncio import socket from asyncio.streams import StreamReader, StreamWriter from .debug import debug_client, debug_server MAX_SIZE = 0x400000 async def handle_server(writer: StreamWriter, server: socket.socket, fp): while (packet := await loop.sock_recv(server, MAX_SIZE)): try: debug_server(packet, fp) except Exception as e: print(f'[S] error: {e}') writer.write(packet) await writer.drain() async def handle_client(reader: StreamReader, writer: StreamWriter): print(reader, writer) server = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) server.connect(('201:4f8c:4ea:0:71ec:6d7:6f1b:a4f9', 25565)) server.setblocking(False) with open("packets.txt", "w") as fp: loop.create_task(handle_server(writer, server, fp)) while (packet := await reader.read(MAX_SIZE)): try: debug_client(packet, fp) except Exception as e: print(f'[C] error: {e}') await loop.sock_sendall(server, packet) loop = asyncio.get_event_loop() def main(): loop.create_task(asyncio.start_server(handle_client, 'localhost', 25565)) loop.run_forever() if __name__ == '__main__': main()