Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communication between node.js servers

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.

like image 315
prakash Avatar asked Jun 19 '13 16:06

prakash


1 Answers

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.

like image 108
eepp Avatar answered Sep 30 '22 09:09

eepp