Search code examples
node.jsnetworkingtcpnetwork-programmingmesh-network

How is a TCP mesh network formed


I want to make a mesh network with 3 nodes, like the following:

B connected to A. 
B connected to C.
A connected to C. 

This is my understanding:

  1. In order for B to connect to A, A will have a TCP server listening on port 8080.

  2. B has a TCP client which will connect to A on 8080.

  3. Now how does A make a connection to C? If C is listening for connections on 8080.

Should every node run both a TCP server and multiple TCP clients to form a mesh?


Solution

  • There is no standard term as TCP server and TCP client, as already hinted in this question's comment section. For reliability purpose, usually we go for TCP protocol as communicating protocol.

    The major difference between TCP and UDP is that former is a connection-oriented protocol for communication, whereas the latter is not connection-oriented.

    NOTE: I'm going to answer this question without having a background in `node.js`.

    In order for B to connect to A, A will have a TCP server listening on port 8080.

    If going for a connection-oriented protocol, A needs to be running a socket application which acts as a server accepting connection requests on port 8080. B will send a connection request to server A.

    B has a TCP client which will connect to A on 8080.

    Similarly, B needs to have a socket application (client-side) which would send A a communication request on server A's port, i.e., 8080 in this case.

    Now how does A make a connection to C. If C is listening for connections on 8080.

    Again, considering a connection-oriented protocol, A can distinctly act as a separate client (using the same / different application), which would send connection request to C. For this, again C needs to be running a socket-server application listening on port 8080 so that A can send a connect request.