-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSocketIOClient.js
More file actions
39 lines (31 loc) · 939 Bytes
/
Copy pathSocketIOClient.js
File metadata and controls
39 lines (31 loc) · 939 Bytes
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
let socketIoClient = SocketIoClient.getInstance("http://192.168.0.111:3000");
socketIoClient.on("connect_error", (error) => {
console.error("连接错误:", error);
});
socketIoClient.on("error", (error) => {
console.error("通用错误:", error);
});
socketIoClient.on("connect_timeout", () => {
console.error("连接超时");
});
socketIoClient.on("connect", function () {
console.log('是否连接成功:', socketIoClient.isConnected());
socketIoClient.on("message", function (data) {
console.log('服务端发来的消息:', data);
});
let str = JSON.stringify({
name: "DeekeScript",
age: 3,
other: {
sex: ["男"]
}
});
socketIoClient.emit("message", str, function (data) {
console.log('确认参数', data);
});
});
socketIoClient.connect();
while (true) {
System.sleep(1000);
console.log('防止脚本终止');
}