You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
648 B

# yum安装python3
# yum install epel-release -y
# yum install python36 -y
# 安装websocket-client方法
# pip install websocket-client -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
import json
import websocket
data = "I am HuangHai!"
url = "ws://10.10.11.202:9000/baseService/mysocket.ws"
websocket.enableTrace(True) #打开跟踪,查看日志
ws = websocket.create_connection(url) # 创建连接
new_data = json.dumps(data, ensure_ascii=False) # 将data转化为字符串
ws.send(new_data) # 发送请求
print(ws.recv()) # 打印服务器响应数据
ws.close() # 关闭连接