Using ZeroMQ with C# on NVIDIA Jetson Nano / Jetson Xavier NX / Jetson TX2 NX Modules - Forecr.io

Using ZeroMQ with C# on NVIDIA Jetson Nano / Jetson Xavier NX / Jetson TX2 NX Modules

Jetson Nano | Jetson TX2 NX | Jetson Xavier NX

10 May 2021
WHAT YOU WILL LEARN?

1- How to install the ZeroMQ Library on Linux operating systems

2- How to communicate with the request-response socket type

3- How to communicate with the Pub-Sub socket type

ENVIRONMENT

Hardware: DSBOARD-NX2

OS: Jetpack 4.5 ( L4T - 32.5)

Language:  C#

In this article, we will show you how to use  ZeroMQ messaging library in C# with .net core on ARM64 which has an operating system as Ubuntu 18.04 for NVIDIA Jetson Nano/Xavier NX/NX2 TX Modules.

ZeroMQ is an open-source universal messaging library and also known as ØMQ, 0MQ, or zmq. For this application, we will be using our carrier board Forecr DSBOARD-NX2 with NVIDIA Jetson Nano module. You can find detailed information about DSBOARD-NX2 from the link below.


https://www.forecr.io/collections/carrier-boards


Now we are ready to create a socket. The sockets are ones that carry messages across various transports such as in-process, inter-process, TCP, and multicast. Also, we can connect N-to-N with patterns like pub-sub, request-response and push-pull.


ZeroMQ library runs smoothly in Ubuntu 18.04 operating system and you can easily download the ZeroMQ to your computer.The first thing we need to do before starting our application is to install zeromq library. To do this, open the terminal and type the following commands:



Now, we have already finished the installation process. Let’s create a sample C# ZeroMQ application using a VS Code. Then, we need to create a new console app with the following command:



Let’s open the application with the VS Code. Then, type the following command:



Next, we should install "System.NetMQ" and "System. Threading". To do this, navigate to the Project Directory and type following command:

We can do zeromq communication and socket opening operations with this library.



We use thread method because our service server will always listen to those who connect to it by the client.



Our main focus in this application is to communicate with each other by using two different communication types of zeromq library; pub-sub and reb-req.

First, let's create a server and a client sock using reb-req communication.

As seen in the codes below, we have one server method and one client method in the main method.



It opens the server side with 5556 port number and allows the client side to connect to it.



The client side connects to the 5556 port number socket with the connect function.



After the connections are made successfully, the messages sent by the server and the client will be output as follows.



Pub-sub, which is another communication method, also listens to the ones that will be connected to the publisher with 5556 port.



Connects to the other socket, subscribe 5566 port



The output will be as follows:




Thank you for reading our blog post.