2

There are two servers and I want to emit some events from server2 to server1 but facing an issue. SERVER1 is working fine when I try to connect it from other client tool(firecamp), but same code is not working when init socket from SERVER2 using socket.io-client. here is code snippets :- SERVER1

socket.io.on('connection', (client) => {

console.log("Socket has been Connected");

client.on("server custom event",(data)=>{
    console.log("custom event");
})
})

OUTPUT OF SERVER1

enter image description here

It continuously connecting and disconnecting socket. but I did not receive any message in SERVER2.

SERVER2 CODE

var ioclient = require("socket.io-client")
var ioc = ioclient.connect('http://localhost:3000');
ioc.on('connect', function () {
// socket connected
console.log("connected");
});
ioc.emit('server custom event', { my: 'data' });

SERVER2 just show the message "server is running on port 8080".

I follow this: Socket IO Server to Server

rveerd
  • 3,620
  • 1
  • 14
  • 30
Hammad Ali
  • 331
  • 3
  • 12

0 Answers0