Skip to content

Instantly share code, notes, and snippets.

@Enforcer
Last active May 25, 2017 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Enforcer/5629c71b4c1cb225873bfd1a459e78d4 to your computer and use it in GitHub Desktop.
Save Enforcer/5629c71b4c1cb225873bfd1a459e78d4 to your computer and use it in GitHub Desktop.
import asyncio
class EchoClientProtocol(asyncio.Protocol):
def __init__(self, message, loop):
self.message = message
self.loop = loop
def connection_made(self, transport):
transport.write(self.message.encode())
print('Data sent: {!r}'.format(self.message))
def data_received(self, data):
print('Data received: {!r}'.format(data.decode()))
def connection_lost(self, exc):
print('The server closed the connection')
print('Stop the event loop')
self.loop.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment