Last active
June 27, 2021 18:56
-
-
Save Snawoot/fb465c98f61814b2885bf0780f7daf25 to your computer and use it in GitHub Desktop.
TCP discard daemon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import asyncio | |
class EchoServerProtocol(asyncio.Protocol): | |
def connection_made(self, transport): | |
self.transport = transport | |
def data_received(self, data): | |
pass | |
async def main(): | |
try: | |
loop = asyncio.get_event_loop() | |
server = await loop.create_server( | |
lambda: EchoServerProtocol(), | |
'0.0.0.0', 9999) | |
async with server: | |
await server.serve_forever() | |
except KeyboardInterrupt: | |
pass | |
if __name__ == "__main__": | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment