Example #1
0
    def _received_datagram(self, address, datagram):
        try:
            message = Message.decode(datagram, remote=address)
        except error.UnparsableMessage:
            self._log.warning("Ignoring unparsable message from %s", address)
            return

        self._mman.dispatch_message(message)
    def _received_datagram(self, address, datagram):
        try:
            message = Message.decode(datagram, remote=address)
        except error.UnparsableMessage:
            self._log.warning("Ignoring unparsable message from %s" %
                              (address, ))
            return

        self._new_message_callback(message)
async def multicast_listen(sock: socket.socket,
                           client_protocol: Context) -> IoT_Resource:
    """Wrap recvfrom in an async generator which yields aiocoap Messages."""
    while True:
        try:
            with suppress(UnparsableMessage):
                raw = sock.recvfrom(1152)
                message = Message.decode(rawdata=raw[0], remote=raw[1][0])
                print('payload: ' + repr(message.payload))
                print('options:')
                for number, option in message.opt._options.items():
                    print(repr(number) + ':')
                    for element in option:
                        print(element.value)
                links = await get_resource_links(client_protocol, message)
                while (message.code is not CONTENT or links is None):
                    raw = sock.recvfrom(1152)
                    message = Message.decode(raw[0], raw[1][0])
                    links = await get_resource_links(client_protocol, message)
                for link in links:
                    yield link
        except BlockingIOError:
            await asyncio.sleep(5)