Socket And App Server On Same Port

[Solved] Socket And App Server On Same Port | Shell - Code Explorer | yomemimo.com
Question : socket and app server on same port

Answered by : dhaval-italiya

// Use below code to app.js/server.js
let httpServer=app.listen(3000, () => console.log(`Server listening on 3000`))
const { Server } = require("socket.io"); var io = new Server(httpServer); global.io=io
io.on('connection', socket => { console.log("connected"); socket.on('disconnect', () => { });
});
// By following below lines you can use socket any where.
global.io.emit('my-page-status', { 'message': 'hello with global variable' });

Source : | Last Update : Fri, 21 Oct 22

Answers related to socket and app server on same port

Code Explorer Popular Question For Shell