当前位置: 首页>>代码示例>>Python>>正文


Python Message.new_ack方法代码示例

本文整理汇总了Python中coapthon.messages.message.Message.new_ack方法的典型用法代码示例。如果您正苦于以下问题:Python Message.new_ack方法的具体用法?Python Message.new_ack怎么用?Python Message.new_ack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coapthon.messages.message.Message的用法示例。


在下文中一共展示了Message.new_ack方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _test_separate

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
    def _test_separate(self, message, notification):
        serializer = Serializer()
        datagram = serializer.serialize(message)
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.sendto(datagram, self.server_address)

        datagram, source = sock.recvfrom(4096)
        host, port = source
        message = serializer.deserialize(datagram, host, port)

        self.assertEqual(message.type, defines.inv_types["ACK"])
        self.assertEqual(message.code, None)
        self.assertEqual(message.mid, self.current_mid - 1)
        self.assertEqual(message.source, source)

        datagram, source = sock.recvfrom(4096)
        host, port = source
        message = serializer.deserialize(datagram, host, port)

        self.assertEqual(message.type, notification.type)
        self.assertEqual(message.code, notification.code)
        self.assertEqual(message.source, source)
        self.assertEqual(message.token, notification.token)
        self.assertEqual(message.payload, notification.payload)
        self.assertEqual(message.options, notification.options)

        message = Message.new_ack(message)
        datagram = serializer.serialize(message)
        sock.sendto(datagram, self.server_address)
        sock.close()
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:32,代码来源:test_coapserver.py

示例2: _test_modular

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
    def _test_modular(self, lst):
        serializer = Serializer()
        for t in lst:
            message, expected = t
            send_ack = False
            if message is not None:
                datagram = serializer.serialize(message)
                self.proto.datagramReceived(datagram, ("127.0.0.1", 5600))
            else:
                send_ack = True

            datagram, source = self.tr.written.pop(0)
            host, port = source
            message = serializer.deserialize(datagram, host, port)
            self.assertEqual(message.type, expected.type)
            if not send_ack:
                self.assertEqual(message.mid, expected.mid)
            self.assertEqual(message.code, expected.code)
            self.assertEqual(message.source, source)
            self.assertEqual(message.token, expected.token)
            self.assertEqual(message.payload, expected.payload)
            self.assertEqual(message.options, expected.options)
            if send_ack:
                message = Message.new_ack(message)
                datagram = serializer.serialize(message)
                self.proto.datagramReceived(datagram, ("127.0.0.1", 5600))

        self.tr.written = []
开发者ID:DavideFoti,项目名称:CoAPthon,代码行数:30,代码来源:test_coapserver.py

示例3: _test_modular

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
    def _test_modular(self, lst):
        serializer = Serializer()
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        for t in lst:
            message, expected = t
            send_ack = False
            if message is not None:
                datagram = serializer.serialize(message)
                sock.sendto(datagram, self.server_address)
            else:
                send_ack = True

            datagram, source = sock.recvfrom(4096)
            host, port = source
            message = serializer.deserialize(datagram, host, port)
            self.assertEqual(message.type, expected.type)
            if not send_ack:
                self.assertEqual(message.mid, expected.mid)
            self.assertEqual(message.code, expected.code)
            self.assertEqual(message.source, source)
            self.assertEqual(message.token, expected.token)
            self.assertEqual(message.payload, expected.payload)
            self.assertEqual(message.options, expected.options)
            if send_ack:
                message = Message.new_ack(message)
                datagram = serializer.serialize(message)
                sock.sendto(datagram, self.server_address)

        sock.close()
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:31,代码来源:test_coapserver.py

示例4: handle_notification

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
 def handle_notification(self, response, client_callback):
     host, port = response.source
     key = hash(str(host) + str(port) + str(response.token))
     self.relation[key] = (response, time.time(), client_callback)
     if response.type == defines.inv_types["CON"]:
         ack = Message.new_ack(response)
         self.send(ack)
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:9,代码来源:coap_protocol.py

示例5: _test_separate

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
    def _test_separate(self, message, notification):
        serializer = Serializer()
        datagram = serializer.serialize(message)
        self.proto.datagramReceived(datagram, ("127.0.0.1", 5600))

        datagram, source = self.tr.written[0]
        host, port = source
        message = serializer.deserialize(datagram, host, port)

        self.assertEqual(message.type, defines.inv_types["ACK"])
        self.assertEqual(message.code, None)
        self.assertEqual(message.mid, self.current_mid + 4)
        self.assertEqual(message.source, source)

        datagram, source = self.tr.written[1]
        host, port = source
        message = serializer.deserialize(datagram, host, port)

        self.assertEqual(message.type, notification.type)
        self.assertEqual(message.code, notification.code)
        self.assertEqual(message.source, source)
        self.assertEqual(message.token, notification.token)
        self.assertEqual(message.payload, notification.payload)
        self.assertEqual(message.options, notification.options)

        self.tr.written = []

        message = Message.new_ack(message)
        datagram = serializer.serialize(message)
        self.proto.datagramReceived(datagram, ("127.0.0.1", 5600))
        self.tr.written = []
开发者ID:DavideFoti,项目名称:CoAPthon,代码行数:33,代码来源:test_coapserver.py

示例6: handle_response

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
 def handle_response(self, response):
     if response.type == defines.inv_types["CON"]:
         ack = Message.new_ack(response)
         self.send(ack)
     key_token = hash(str(self.server[0]) + str(self.server[1]) + str(response.token))
     if key_token in self.sent_token.keys():
         self.received_token[key_token] = response
         req, timestamp, callback, client_callback = self.sent_token[key_token]
         key = hash(str(self.server[0]) + str(self.server[1]) + str(req.mid))
         self.received[key] = response
         callback(req.mid, client_callback)
开发者ID:johanzander,项目名称:CoAPthon,代码行数:13,代码来源:coap_protocol.py

示例7: send_ack

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
    def send_ack(self, request):
        # Handle separate
        """
        Sends an ACK message for the request.

        :param request: [request] or request
        """
        if isinstance(request, list):
            request = request[0]
        ack = Message.new_ack(request)
        host, port = request.source
        self._parent.send(ack, host, port)
        request.acknowledged = True
开发者ID:DavideFoti,项目名称:CoAPthon,代码行数:15,代码来源:message.py

示例8: send_ack

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
    def send_ack(self, request):
        # Handle separate
        """
        Sends an ACK message for the request.

        :param request: [request, sleep_time] or request
        """
        if isinstance(request, list):
            if len(request) == 2:
                time.sleep(request[1])
            request = request[0]
        ack = Message.new_ack(request)
        host, port = request.source
        if not request.acknowledged:
            self._parent.send(ack, host, port)
            request.acknowledged = True
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:18,代码来源:message.py

示例9: send_ack

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
    def send_ack(self, list_request):
        """
        Send an ack to the client. Used mostly with separate.

        :param list_request: the request to be acknowledge.
        :type list_request: [Request] or Request
        """

        if isinstance(list_request, list):
            request = list_request[0]
        else:
            request = list_request
        del self.timer[request.mid]
        host, port = request.source
        ack = Message.new_ack(request)
        self.send(ack, host, port)
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:18,代码来源:forward_coap_protocol.py

示例10: handle_response

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
 def handle_response(self, response):
     if response.type == defines.inv_types["CON"]:
         ack = Message.new_ack(response)
         self.send(ack, self._endpoint)
     key_token = hash(str(self._endpoint[0]) + str(self._endpoint[1]) + str(response.token))
     if key_token in self.sent_token.keys():
         self.received_token[key_token] = response
         req = self.sent_token[key_token]
         key = hash(str(self._endpoint[0]) + str(self._endpoint[1]) + str(req.mid))
         timer, counter = self.call_id[key]
         timer.cancel()
         self.received[key] = response
         self.condition.acquire()
         self._response = response
         self.condition.notify()
         self.condition.release()
开发者ID:DavideFoti,项目名称:CoAPthon,代码行数:18,代码来源:coap_synchronous.py

示例11: send_ack

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
    def send_ack(self, list_request):
        """
        Send an ack to the client. Used mostly with separate.

        :param list_request: the request to be acknowledge.
        :type list_request: [Request] or Request
        """

        if isinstance(list_request, list):
            request = list_request[0]
        else:
            request = list_request
        key_timer = hash(str(request.source[0]) + str(request.source[1]) + str(request.mid))
        if self.timer.get(key_timer) is not None:
            del self.timer[key_timer]
        host, port = request.source
        ack = Message.new_ack(request)
        self.send(ack, host, port)
开发者ID:DavideFoti,项目名称:CoAPthon,代码行数:20,代码来源:forward_coap_protocol.py

示例12: handle_request

# 需要导入模块: from coapthon.messages.message import Message [as 别名]
# 或者: from coapthon.messages.message.Message import new_ack [as 别名]
    def handle_request(self, request):
        """
        Handles requests.

        :param request: the request
        :return: the response
        """
        host, port = request.source
        key = hash(str(host) + str(port) + str(request.mid))
        if key not in self._parent.received:
            if request.blockwise:
                # Blockwise
                last, request = self._parent.blockwise_transfer(request)
                if last:
                    self._parent.received[key] = (request, time.time())
                    return request
            else:
                self._parent.received[key] = (request, time.time())
                return request
        else:
            request, timestamp = self._parent.received.get(key)
            request.duplicated = True
            self._parent.received[key] = (request, timestamp)
            try:
                response, timestamp = self._parent.sent.get(key)
            except TypeError:
                response = None
            if isinstance(response, Response):
                return response
            elif request.acknowledged:
                ack = Message.new_ack(request)
                return ack
            elif request.rejected:
                rst = Message.new_rst(request)
                return rst
            else:
                # The server has not yet decided, whether to acknowledge or
                # reject the request. We know for sure that the server has
                # received the request though and can drop this duplicate here.
                return None
开发者ID:johanzander,项目名称:CoAPthon,代码行数:42,代码来源:request.py


注:本文中的coapthon.messages.message.Message.new_ack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。