With the Socket.IO library, you should open a port and listen to the request using the following lines of code. Initially, we were directly using app.listen(), but now, we will pass that function as a listener for sockets:
val io = require("socket.io").listen(app.listen(port, { println("Chat app listening on port http://localhost:$port") }))
The server will listen to the following events and based on those events, it will perform certain tasks:
- Listen to the successful socket connection with the client
- Listen for the new user login events
- Whenever a new user joins the chat, add it to the online users chat list and broadcast it to every client so that they will know that a new member has joined the chat
- Listen to the ...