コード例 #1
0
def ws_connect():
    is_sigint_up = False
    rt = read_info.ReadInfo()
    web = rt.get_device_ip()
    port = rt.get_port()
    url = web + ":" + port
    try:
        ws = create_connection(url, timeout=10)  #建立设备连接

        rm = read_message.ReadMessage()
        data_login = rm.get_data("登录设备", "login_monitor")
        print("step 1、登录设备/监控者")
        t = c.checkAction(ws, data_login)

        # rm=read_message.ReadMessage()
        # data_query_position=rm.get_data("31","query_position")
        while (is_sigint_up == False):
            if ws.connected:
                print("服务:%s连接成功!" % url)
                # t=ws.recv()
                t = json.loads(ws.recv())
                print(t)
                # print("查询脚本行数位置。")
                # c.checkAction(ws,data_query_position)
        ws.close()
    except Exception as e:
        print("websocket连接失败:%s" % e)
        pass
コード例 #2
0
 def setUp(self):
     rt = read_info.ReadInfo()
     web = rt.get_device_ip()
     port = rt.get_port()
     url = web + ":" + port
     try:
         self.ws = create_connection(url, timeout=10)  #建立设备连接
         if self.ws.connected:
             print("服务:%s连接成功!" % url)
     except Exception as e:
         print("websocket连接失败:%s" % e)
         pass