- JavaScript
- Node.js
- Express.js
- Socket.IO
Install npm packages:
$ npm install
Run the app with this command:
$ nodemon server.js
You may visit the application on browser with the URL: http://localhost:3000
Each new connection is assigned a random 20-characters identifier.
This identifier is synced with the value on the server-side.
// server-side
io.on("connection", (socket) => {
console.log(socket.id); // x8WIv7-mJelg7on_ALbx
});
// client-side
socket.on("connect", () => {
console.log(socket.id); // x8WIv7-mJelg7on_ALbx
});
socket.on("disconnect", () => {
console.log(socket.id); // undefined
});