NEP+ Docs
  • NEP+ middleware documentation
  • Developer Tools
    • NEP CLI
  • User interfaces
    • Install NEP+ App (Windows)
    • Install NEP+ App (macOS)
    • NEP+ App (0.0.4) - Deprecated
  • Concepts for developers
    • Message Format
    • Tutorials for developers
      • Connecting Multiple Scripts on the Same Computer using NEP+ Tools: A Step-by-Step Tutorial
      • Connecting 2 scripts in a local network (e.g., two computers on the same Wifi network)
      • Connecting ROS to non-ROS nodes using NEP+ tools
  • Programming enviroments
    • Python
    • C# (Unity)
    • C# (Visual Studio)
    • Javascript (Node.js)
    • Java/Kotlin (Android Studio)
    • Java (Netbeans)
    • C++ (Visual Studio)
  • Other tutorials
    • Pepper & NAO robots
      • Using Pepper without Pepper in Choregraphe
      • Install Pepper/NAO SDK
  • Code examples
    • Sending images from Python and Opencv
Powered by GitBook
On this page
  • Method 1: Direct
  • Connecting Computer A and Computer B
  • Method 2: Using NEP CLI (recommended)
  • Connecting Computer A and Computer B
  • Method 3: Using NEP+ App (soon)
  1. Concepts for developers
  2. Tutorials for developers

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:

Method
Requirements
Advantages
Disadvantages

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.

NEP+ app installed

Same that NEP CLI

Same that NEP CLI

Where it is recommended to use these methods?

Method
When is recommended?

When you only need to connect two modules without caring about the scalability of the project

When will you use your modules in many projects and care about reusability and scalability

Same as nep-cli but for users preferring a user interface

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.

The command ipconfig (in Windows) or ifconfig (in Linux and OSX) can be used to know the IP address of your computer.

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

import nep
import time

# Create a new nep node
node = nep.node('publisher') 
# Set a direct connection using port <3000> and in <'one2many'> mode
# Important: 	You need to change the IP address <'127.0.0.1'> by 
# 		the IP address of your PC running the publisher node
conf = node.direct(ip = '127.0.0.1', port =  3000, mode ='one2many') 
# Create a new publisher with the topic <'test'>
pub = node.new_pub('test','json',conf)

i = 0
while True:
	# You will put your code here, which is doing some analysis...
	i = i + 1
	# The result will be sent using the JSON format (just create a python dictionary)
	msg = {'result':i}
	# Send the message with the next line	
	pub.publish(msg)
	# A small time.sleep is used for visualization purposes 		
	time.sleep(.5)

Soon

Soon

Soon

The code required in Computer B (Subscriber) is shown below.

import nep
import time

# Create a new nep node
node = nep.node("receiver")     
# Set a direct connection using port <3000> and in <'one2many'> mode
# Important: 	You need to change the IP address <'127.0.0.1'> by 
# 		the IP address of you PC running the publisher node                                                   
conf = node.direct(ip = "127.0.0.1", port =  3000, mode ="one2many")                         
# Create a new nep subscriber with the topic <'test'>
sub = node.new_sub('test', "json", conf) 

while True:
    # Read data in a non-blocking mode
    s, msg = sub.listen() 
    # if s == True, then there is data in the socket      
    if s:                       
        print(msg)
    else:
        # An small sleep will reduce computational load
        time.sleep(.0001)

Soon

Soon

Soon

Soon

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.

Using NEP CLI or NEP+ App all communication is performed in a many2many mode (i.e., multiple publishers can be connected to multiple subscribers using the same topic).

Connecting Computer A and Computer B

The code required in Computer A (nep publisher) is shown below

import nep
import time

# Create a new nep node
node = nep.node('publisher') 
# Important: 	You need to change the IP address <'127.0.0.1'> by 
# 		the IP address of PC running NEP CLI
conf = node.hybrid('127.0.0.1') 
# Create a new publisher with the topic <'test'>
pub = node.new_pub('test','json',conf)

i = 0
while True:
	# You will put your code here, which is doing some analysis...
	i = i + 1
	# The result will be sent using the JSON format (just create a python dictionary)
	msg = {'result':i}
	# Send the message with the next line	
	pub.publish(msg)
	# A small time.sleep is used for visualization purposes 		
	time.sleep(.5)

Soon

Soon

Soon

The code required in Computer B (nep subscriber) is shown below.

import nep
import time

# Create a new nep node
node = nep.node("receiver")     
# Important: 	You need to change the IP address <'127.0.0.1'> by 
# 		the IP address of PC running NEP CLI                                                 
conf = node.hybrid('127.0.0.1')                         
# Create a new nep subscriber with the topic <'test'>
sub = node.new_sub('test', "json", conf) 

while True:
    # Read data in a non-blocking mode
    s, msg = sub.listen() 
    # if s == True, then there is data in the socket      
    if s:                       
        print(msg)
    else:
        # An small sleep will reduce computational load
        time.sleep(.0001)

Soon

Soon

Soon

Soon

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 1 year ago

Direct
NEP CLI
Nep+ App
Direct
NEP CLI
Nep+ App
Example of how to set IP values for direct method
Example using NEP-CLI
Example using NEP-CLI and multiple computers