aiohttp.web.MsgType.text

Here are the examples of the python api aiohttp.web.MsgType.text taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: sockjs Source File: rawwebsocket.py
Function: client
    @asyncio.coroutine
    def client(self, ws, session):
        while True:
            msg = yield from ws.receive()

            if msg.tp == web.MsgType.text:
                if not msg.data:
                    continue

                yield from self.session._remote_message(msg.data)

            elif msg.tp == web.MsgType.close:
                yield from self.session._remote_close()
            elif msg.tp == web.MsgType.closed:
                yield from self.session._remote_closed()
                break

Example 2

Project: sockjs Source File: websocket.py
Function: client
    @asyncio.coroutine
    def client(self, ws, session):
        while True:
            msg = yield from ws.receive()

            if msg.tp == web.MsgType.text:
                data = msg.data
                if not data:
                    continue

                if data.startswith('['):
                    data = data[1:-1]

                try:
                    text = loads(data)
                except Exception as exc:
                    yield from session._remote_close(exc)
                    yield from session._remote_closed()
                    yield from ws.close(message=b'broken json')
                    break

                yield from session._remote_message(text)

            elif msg.tp == web.MsgType.close:
                yield from session._remote_close()
            elif msg.tp == web.MsgType.closed:
                yield from session._remote_closed()
                break