-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
65 lines (55 loc) · 1.98 KB
/
index.html
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
61
62
63
64
65
<!DOCTYPE html>
<html>
<head>
<title>Socket Client</title>
</head>
<body>
<h1>Socket Client</h1>
<p>Please check the console in developer tools</p>
<button onclick="connectSockets()">Connect Socket</button>
<br />
<br />
<button onclick="sendQuestion()">Send Question</button>
<br />
<br />
<button onclick="closeSockets()">Close Sockets</button>
<script type="module">
import { io } from "https://cdn.socket.io/4.3.2/socket.io.esm.min.js";
let socket1;
let socket2;
let socket3;
window.connectSockets = () => {
socket1 = io("http://localhost:3000/socket", {
transports: ["websocket"]
});
socket2 = io("http://localhost:3001/socket", {
transports: ["websocket"]
});
socket3 = io("http://localhost:3002/socket", {
transports: ["websocket"]
});
socket1.on("question", (data) => {
console.log("Socket1 question: ", data);
});
socket2.on("question", (data) => {
console.log("Socket2 question: ", data);
});
socket3.on("question", (data) => {
console.log("Socket3 question: ", data);
});
}
window.closeSockets = () => {
socket1?.close();
socket2?.close();
socket3?.close();
}
window.sendQuestion = () => {
if (!socket1) {
alert("Please connect socket!");
return;
}
socket1?.emit("question", "How are you?");
}
</script>
</body>
</html>