Communication between node.js servers

I'm a little new to node.js. My question is, can I connect two node.js servers? these 2 servers handle clients and perform an individual action. I want to establish a connection between these two servers so that these two servers can share this status with each other.

Can anybody help me?

it's a bit like this

server1 ==> room1 [client1, client2, client3]

server2 ==> room2 [client4, client5, client6]

here I want to make a connection between these two servers.

+4
source share
1 answer

Of course: just use the socket , as with any other programming language capable of network communication.

One of the servers will need to listen on the TCP port (using net.createServer ), and the other will connect to it using net.connect .

It is easy if you really only have two servers. If you have more, you will need either the main β€œreferee”, i.e. A relay (listening) server that receives messages from other servers and sends them to real recipients, or a mesh network (not a good starting point if you are new to the network).

JsonSocket seems like an interesting project for sending JSON messages using raw TCP sockets, although I have not tested it myself.

+5
source

Source: https://habr.com/ru/post/1487085/


All Articles