Connecting 2 scripts in a local network (e.g., two computers on the same Wifi network)
This tutorial will show you how to connect two or more computers that are on the same local network (e.g., connected to the same Wifi network) using NEP+ tools.
For Windows users: In some computers, the antivirus will not allow local network connections using ZMQ sockets. A fast solution for testing purposes can be to disable the antivirus.
We will explore three different methods:
NEP libraries installed (also required in the other methods)
Less tools to install
It can be annoying to deal with IP addresses, communication modes and port numbers
Node.js and nep-cli package installed
You don't need to care anymore about port numbers and modes.
You need to remember and use the same IP address for all your nodes.
Where it is recommended to use these methods?
Method 1: Direct
Connecting two or more modules/nodes are executed on different devices/computers using a direct mode requires knowing the IP address of one of the computers and the port in which the connection is made.
Remember: All the devices/computers must be in the same Wifi or Ethernet local network.
Connecting Computer A and Computer B
To ensure proper configuration, replace the IP address 127.0.0.1 in the examples with the correct IP of your computer within the Wi-Fi or Ethernet network.
In the case of the one2many mode, which involves a single publisher and multiple subscribers, you need to set the IP address of the computer executing the publisher in both scripts executing the publisher and subscriber.
In the case of the many2one mode, which involves multiple publishers sending messages to a single subscriber, you need to set the IP address of the computer executing the subscriber in both scripts executing the publisher and subscriber.
To use a many2many mode it is required to use the NEP-CLI or NEP+ App method.
The code required in Computer A (Publisher) is shown below
The code required in Computer B (Subscriber) is shown below.
When employing the direct method, it is crucial to accurately configure the IP values in both scripts. This process might pose a slight challenge initially. The following illustration offers a clear example. It's important to keep in mind that both scripts on Computer A and Computer B should share identical IP addresses and modes (either one2many or many2one).
Method 2: Using NEP CLI (recommended)
By utilizing the NEP CLI, there is no need to manage multiple IP addresses and port numbers. Nevertheless, it is necessary to configure the same IP address for each script.
Connecting Computer A and Computer B
The code required in Computer A (nep publisher) is shown below
The code required in Computer B (nep subscriber) is shown below.
The next figure shown an example of how to configuarte your application. NEP-CLI must be executed in one computer and all the script must use be configured to communicate to the same IP address. That IP address must be the same that the PC executing NEP-CLI.
This approach can be extended to multiple computers as shown in the next figure.
Method 3: Using NEP+ App (soon)
Soon
Last updated