python实现的WebSocket客户端

code

#coding=utf-8
import json
import time
from websocket import create_connection

ws = create_connection("ws://x.x.x.x:8090/haiyou/device")
print("Sending 'Hello, World'...")
t=str(time.time()).split(".")[0]
params={
    "version": 1,
    "msgNo": "1",
    "machNo": "U040119110001",
    "cmd": 1,
    "time": 1574064604418
}

ws.send(json.dumps(params))
print("Sent")
print("Reeiving...")
result = ws.recv()
print("Received '{}'".format(result))


params={
    "version": 1,
    "msgNo": t,
    "machNo": "U040119110001",
    "cmd": 7,
    "time": t,
    "data": {
        "userId": 8,
        "companyType": 3,
        "before": 0,
        "after": 100,
        "openTime": t,
        "closeTime": t
    }
}

ws.send(json.dumps(params))
print("Sent")
print("Reeiving...")
result = ws.recv()
print("Received '{}'".format(result))


ws.close()

参考:

https://blog.csdn.net/qq562029186/article/details/81203893

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/11990209.html