forked from WhileBug/DecaySeeker_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcpClient.py
60 lines (52 loc) · 1.03 KB
/
tcpClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 导入 socket、sys 模块
import socket
import sys
import json
sendMsg = {
"method":"report",
"clientToken":235,
"params":[
{
"position":1,
"ph":5.5,
"voltage":10.32
},
{
"position":2,
"ph":5.5,
"voltage":10.32
},
{
"position":3,
"ph":5.5,
"voltage":10.32
},
{
"position":4,
"ph":5.5,
"voltage":10.32
},
{
"position":5,
"ph":5.5,
"voltage":10.32
},
{
"position":6,
"ph":5.5,
"voltage":10.32
}
]
}
# 创建 socket 对象
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 获取本地主机名
host = '1.15.106.25'
# 设置端口号
port = 8848
# 连接服务,指定主机和端口
s.connect((host, port))
# 发送收集到的数据
sendMsgTxt = json.dumps(sendMsg)
s.send(sendMsgTxt.encode('utf-8'))
s.close()