Can anyone help me to figure out this code .I'm new to Socket.io I just wanted to see how actually client and server interacts. Code in Express.js is here :
const express = require('express');
const router = express.Router();
const io = require('socket.io')();
const iio = require('socket.io-client');
const po = iio("http://localhost:5000");
po.connect();
const nsp = io.of("http://localhost:5000");
router.get ('/',async (req,res)=> {
try {
nsp.emit('connec', {message:"response from socket"})
po.on('connec', (message) => {
console.log("socket"+message);
})
res.send({message:"its get request"});
} catch(error) {
console.error(error.message);
res.status(500).send("INTERNAL SERVER ERROR");
}
})
module.exports = router;
thanks in advance.
I tried to make a web-socket using Socket.io but it is not listening events properly .