forked from ValeriiSyrov/scaling_socketio_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
30 lines (18 loc) · 606 Bytes
/
client.js
File metadata and controls
30 lines (18 loc) · 606 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
import { io } from "socket.io-client";
import { createServer } from "http";
const PORT = process.env.PORT;
const socket = io('http://localhost:3005', {
transports: [ "websocket" ]
});
socket.on("connect", () => {
console.log(socket.id);
socket.on("answer", (data) => {
console.log(data.text);
});
const requestListener = async function (req, res) {
socket.emit("message", `My message ${socket.id} `);
res.end('Sent the message')
}
const httpServer = createServer(requestListener);
httpServer.listen(PORT, () => console.log('server client starts'));
});