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


Python MqttClient.conn_is_alive方法代码示例

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


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

示例1: test_251

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_251(self):
        tfs = [
            ("+"         , True),
            ("/+"        , True),
            ("+/"        , True),
            ("+/foo"     , True),
            ("/foo/+"    , True),
            ("/foo/+/"   , True),
            ("/foo/+/bar", True),
            ("+/foo/bar" , True),
            ("foo+"      , False),
            ("foo+/bar"  , False),
            ("+foo/bar"  , False),
            ("foo/+bar"  , False),
            # ~
            ("++"        , False),
            ("foo/++/bar", False),
        ]

        for (tf, isvalid) in tfs:
            sub = MqttClient("conformity:{seq}", connect=4)
            sub.subscribe(tf, qos=0, read_response=False)
            ack = sub.recv()

            if (isvalid and not isinstance(ack, EventSuback)) or \
                    (not isvalid and (ack is not None or sub.conn_is_alive())):
                debug("{0}: {1} ({2})".format(tf, ack, sub.conn_is_alive()))
                return False

            sub.disconnect()

        return True
开发者ID:gbour,项目名称:wave,代码行数:34,代码来源:020_v311.py

示例2: test_112

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_112(self):
        ## PINGREG
        c = MqttClient("conformity:{seq}", raw_connect=True)
        evt = c.connect(version=4)

        # flags shoud be 0
        c.forge(NC.CMD_PINGREQ, 4, [], send=True)
        if c.conn_is_alive():
            debug("connection still alive")
            return False

        ## SUBSCRIBE
        c = MqttClient("conformity2:{seq}", raw_connect=True)
        evt = c.connect(version=4)

        # flags shoud be 2
        c.forge(NC.CMD_SUBSCRIBE, 3, [
            ('uint16', 42),         # identifier
            ('string', '/foo/bar'), # topic filter
            ('byte'  , 0)           # qos
        ], send=True)
        if c.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:28,代码来源:020_v311.py

示例3: test_021

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_021(self):
        """
            throwing "anonymous" exception on binary pattern matching
            (mqtt_msg:decode_connect2())
        """
        client  = MqttClient("rabbit:{seq}", raw_connect=True)
        client.forge(NC.CMD_CONNECT, 0, [
            ('string', 'MQTT'),
            ('byte'  , 4),         # protocol level
            ('byte'  , 4),         # will=1
            ('uint16', 60),        # keepalive
            ('string', client._c.client_id),
            ('string', '/will/topic'), # will-topic
        ], send=True)
        if client.conn_is_alive():
            debug("connection still alive")
            return False

        client  = MqttClient("rabbit:{seq}", raw_connect=True)
        client.forge(NC.CMD_CONNECT, 0, [
            ('string', 'MQTT'),
            ('byte'  , 4),         # protocol level
            ('byte'  , 4),         # will=1
            ('uint16', 60),        # keepalive
            ('string', client._c.client_id),
            ('string', '/will/topic'), # will-topic
            ('uint16', 4),         # 4 bytes msg, BUT not message following
        ], send=True)
        if client.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:35,代码来源:021_lastwill.py

示例4: test_213

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_213(self):
        c = MqttClient("conformity:{seq}", connect=4)
        c.publish("foo/+/bar", "", qos=0)
        if c.conn_is_alive():
            debug("connection still alive")
            return False

        c = MqttClient("conformity:{seq}", connect=4)
        c.publish("foo/#/bar", "", qos=0)
        if c.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:16,代码来源:020_v311.py

示例5: test_008

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_008(self):
        client  = MqttClient("rabbit:{seq}", raw_connect=True)
        client.forge(NC.CMD_CONNECT, 0, [
            ('string', 'MQTT'),
            ('byte'  , 4),         # protocol level
            ('byte'  , 28),        # will=1, will-qos=3
            ('uint16', 60),        # keepalive
        ], send=True)
        if client.conn_is_alive():
            debug("connection still alive")
            return False

        client  = MqttClient("rabbit:{seq}", raw_connect=True)
        client.forge(NC.CMD_CONNECT, 0, [
            ('string', 'MQTT'),
            ('byte'  , 4),         # protocol level
            ('byte'  , 12),        # will=1, will-qos=1
            ('uint16', 60),        # keepalive
            ('string', client._c.client_id),   # clientid
            ('string', '/foo/bar'),# will topic
            ('uint16', 0),         # will payload len
            ('bytes' , ''),        # will payload
        ], send=True)

        evt = client.recv()
        if not isinstance(evt, EventConnack):
            debug(evt)
            return False

        client.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:33,代码来源:021_lastwill.py

示例6: test_109

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_109(self):
        c = MqttClient("conformity:{seq}")
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.connect(('127.0.0.1', 1883))
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
            sock.setblocking(0)
        except Exception as e:
            debug(e)
            return False

        c._c.sock = sock

        pkt = MqttPkt()
        pkt.command = NC.CMD_CONNECT
        pkt.remaining_length = 12 + 26 # client_id = "ff"
        pkt.alloc()

        pkt.write_string("MQTT")
        pkt.write_byte(NC.PROTOCOL_VERSION_4)
        pkt.write_byte(0)      # flags
        pkt.write_uint16(10)   # keepalive
        pkt.write_string("ABCDEFGHIJKLMNOPQRSTUVWXYZ") # client id - 26 chars

        c._c.packet_queue(pkt)
        c._c.packet_write()
        c._c.loop()

        if c.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:35,代码来源:020_v311.py

示例7: test_223

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_223(self):
        c = MqttClient("conformity-sub:{seq}", connect=4)
        c.disconnect()

        if c.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:11,代码来源:020_v311.py

示例8: test_270

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_270(self):
        pub = MqttClient("luser:{seq}", connect=4)
        pub.publish("$foo/bar", "test1")

        if pub.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:11,代码来源:020_v311.py

示例9: test_220

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_220(self):
        c = MqttClient("conformity:{seq}", connect=4)

        c.forge(NC.CMD_UNSUBSCRIBE, 2, [
            ('uint16', 10),         # identifier
            # NOT TOPIC FILTER/QOS
        ], send=True)
        if c.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:14,代码来源:020_v311.py

示例10: test_212

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_212(self):
        c = MqttClient("conformity:{seq}", connect=4)

        # qos 1
        c.forge(NC.CMD_PUBLISH, 2, [], send=True)
#            ('uint16', 0),          # identifier
#        ], send=True)
        if c.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:14,代码来源:020_v311.py

示例11: test_211

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_211(self):
        c = MqttClient("conformity:{seq}", connect=4)

        c.forge(NC.CMD_PUBLISH, 6, [
            ('string', '/foo/bar'), # topic
            ('uint16', 0),          # identifier
        ], send=True)
        if c.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:14,代码来源:020_v311.py

示例12: test_215

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_215(self):
        c = MqttClient("conformity:{seq}", connect=4)
        c.forge(NC.CMD_SUBSCRIBE, 2, [
            ('uint16', 42),         # identifier
            ('string', '/foo/bar'), # topic filter
            ('byte'  , 3)           # qos
        ], send=True)
        if c.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:14,代码来源:020_v311.py

示例13: test_010

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_010(self):
        client  = MqttClient("rabbit:{seq}", raw_connect=True)
        client.forge(NC.CMD_CONNECT, 0, [
            ('string', 'MQTT'),
            ('byte'  , 4),         # protocol level
            ('byte'  , 32),        # will=0, will-retain=1
            ('uint16', 60),        # keepalive
        ], send=True)
        if client.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:15,代码来源:021_lastwill.py

示例14: test_115

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_115(self):
        c = MqttClient("conformity:{seq}", raw_connect=True)
        evt = c.connect(version=4)

        c.forge(NC.CMD_UNSUBSCRIBE, 2, [
            ('uint16', 0),         # identifier
            ('string', '/foo/bar'), # topic filter
        ], send=True)
        if c.conn_is_alive():
            debug("connection still alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:15,代码来源:020_v311.py

示例15: test_255

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import conn_is_alive [as 别名]
    def test_255(self):
        c = MqttClient("conformity:{seq}", connect=4)
        c.subscribe("", qos=0)

        if c.conn_is_alive():
            debug("connection still alive")
            return False

        c = MqttClient("conformity:{seq}", connect=4)
        c.unsubscribe("")

        if c.conn_is_alive():
            debug("connection still alive")
            return False

        c = MqttClient("conformity:{seq}", connect=4)
        c.publish("", "", qos=0)

        if c.conn_is_alive():
            debug("connection stil alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:25,代码来源:020_v311.py


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