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
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