File size: 513 Bytes
d60b4e5
 
 
 
 
 
 
 
 
 
 
 
 
 
5d2be44
d60b4e5
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const app = require("express")();
const http = require("http").createServer(app);

app.get('/',(req,res)=>{
    res.send("Chat server is up and running!");
})

// Socket logic
const socketio = require("socket.io")(http);

//adding on connection event listener
socketio.on("connection",(userSocket)=>{
    //socket listening for send_message
    userSocket.on("send_message",(data)=>{
        console.log("sent a message!");
        userSocket.broadcast.emit("receive_message",data);
    });
});

http.listen(8080)