Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import asyncio
class Protocol(object):
def connection_made(self, transport):
print("connection_made: {}".format(transport))
transport.abort()
def connection_lost(self, why):
print("connection_lost: {}".format(why))
def make_proto():
print("creating protocol")
return Protocol()
async def main(loop):
f = loop.create_connection(make_proto, host="localhost", port="8080")
try:
transport, proto = await f
print("transport: {}".format(transport))
print("proto: {}".format(proto))
except Exception as e:
print("error: {}".format(e))
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
@meejah

This comment has been minimized.

Copy link
Owner Author

@meejah meejah commented Jun 20, 2019

Output when there's a thing listening on 8080:

creating protocol
connection_made: <_SelectorSocketTransport fd=7 read=idle write=<idle, bufsize=0>>
connection_lost: None
transport: <_SelectorSocketTransport closed fd=7>
proto: <__main__.Protocol object at 0x7fae386874a8>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.