I'm quite a bit new to node.js. I have question, can we connect two node.js servers? these 2 servers handle clients and perform there individual action I want to establish a connection between these two servers so that these 2 servers can share there status to each other.
Can anyone please help me?
it is somewhat like this
server1 ==> room1[client1, client2,client3]
server2 ==> room2[client4,client5, client6]
here I want to make a communication between these two servers.
Sure: just use a socket as you would with any other programming language that's capable of network communications.
One of the servers will need to listen on a TCP port (using net.createServer
) and the other one connects to it using net.connect
.
This is easy if you really only have two servers. If you have more, you will need either a main "arbiter", i.e. a (listening) relay server that receives messages from other servers and transfer them to real recipients, or a mesh network (not a good starting point if you're a networking newbie).
JsonSocket seems to be an interesting project for transfering JSON messages using raw TCP sockets, although I didn't test it myself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With