Esempio n. 1
0
    def server_handler(reader, writer):
        """Echo server"""

        tfe = TCPFrameEndpoint(reader, writer)

        # Read a frame:
        frame = yield from tfe.recv()
        assert frame == b'abc'

        # Read a frame:
        frame = yield from tfe.recv()
        assert frame == b''

        # Read a frame:
        frame = yield from tfe.recv()
        assert frame == b'abcd'

        # Read a frame:
        frame = yield from tfe.recv()
        assert frame == b'abcd'

        res.append('sending_frame')
        # Write a frame:
        yield from tfe.send(b'1234')

        # Last frame was cut in the middle (The connection was closed),
        # therefore we expect to get a None here:
        frame = yield from tfe.recv()
        assert frame is None

        res.append('got_none')
Esempio n. 2
0
    def server_handler(reader, writer):
        """Echo server"""

        tfe = TCPFrameEndpoint(reader, writer)

        # Read a frame:
        frame = yield from tfe.recv()
        # Send the frame back to client:
        yield from tfe.send(frame)
Esempio n. 3
0
    def server_handler(reader, writer):
        """Echo server"""

        tfe = TCPFrameEndpoint(reader, writer, max_frame_len=4)

        # Read a frame:
        frame = yield from tfe.recv()
        assert frame == b'abc'

        # Read a frame:
        frame = yield from tfe.recv()
        assert frame == b''

        # Read a frame. The frame should be too large for the chosen
        # max_frame_len=4, so we expect to get None here:
        frame = yield from tfe.recv()
        assert frame == None

        res.append('got_none')
Esempio n. 4
0
    def client():
        CLIENT_MESS = b'This is a mess'
        reader, writer = yield from \
                asyncio.open_connection(host=addr,port=port)
        tfe = TCPFrameEndpoint(reader, writer)
        yield from tfe.send(CLIENT_MESS)
        frame = yield from tfe.recv()
        assert frame == CLIENT_MESS
        # Append True to list of results:
        res.append(True)

        # Close client:
        yield from tfe.close()