Spaces:
Sleeping
Sleeping
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) |