Reputation: 151
I am not able to establish the connection to Socket.IO in node server. My server is successfully started with Socket.IO but during the connection to Socket, I am not getting the console logs.
this.server.listen(this.port, () => {
console.log(`Server is running on ${this.port} with process id ${process.pid}`)
});
this.io.on('connection', (socket: any) => {
console.log(`Connected client on port ${this.port}`);
socket.on('messsage', (msg: Message) => {
console.log(`Data: ${msg}`);
socket.emit('message', msg);
});
socket.on('disconnect', () => {
console.log(`Client Disconnected`);
});
});
Upvotes: 1
Views: 81
Reputation: 1341
try to change your code:
var socket = io.connect('localhost');
to
var socket = io.connect('http://localhost:port');
Upvotes: 1