Last active
August 29, 2015 13:57
-
-
Save asvetlov/9810295 to your computer and use it in GitHub Desktop.
This file contains 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
import asyncio | |
class A: | |
def __init__(self, reader, writter): | |
self.reader, self.writer = reader, writter | |
@asyncio.coroutine | |
def read_packet(self): | |
bsize = yield from self.reader.readexactly(4) | |
size = int(bsize) | |
data = yield from self.reader.readexactly(size) | |
return data | |
@coroutine | |
@classmethod | |
def connect(cls, host, port): | |
reader, writter = yield from asyncio.open_connection(host, port) | |
return cls(reader, writer) | |
@coroutine | |
def go(): | |
a = yield from A.connect('localhost', 5555) | |
data = yield from a.read_packet() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment