2- Socket.IO in a nutshell
3- How to create a new NodeJS application using ExpressJS
4- How to install socket.IO library on NodeJS applications
5- How to communicate between server-side and client-side using Socket.IO
OS: JetPack 4.5 ( L4T - 32.5)
In this article, we will show you how to use Socket.IO messaging library in NodeJS on ARM64 which has an operating system as Ubuntu 18.04 for NVIDIA Jetson Nano & Xavier NX & TX2 NX Modules.
We will use our carrier board, Forecr DSBOARD-NX2 with NVIDIA Jetson Xavier NX module. You can find detailed information about DSBOARD-NX2 from the link below.
First of all, NodeJS must be installed on our computer to use socket.IO. “nodejs -v” with that command, we can see which version we have installed, and also, we can verify NodeJS installed.
If NodeJS is not installed, you can learn how to install it from our article on the link below.
After verifying our NodeJS version, let’s run a sample Socket.IO sample using a NodeJS. First, create a folder named socketIOSample.
Now, navigate to the project directory with the following command:
We will create our NodeJS web application with the express.js library. ExpressJS is an open-source back-end web application framework for Node.js. We can design easily for building web applications and API’s.
Let's create our application with express.js by entering the following commands.
Use the npm init command to create a package.json file for our application.
We enter index.js our name of the main file.
Now install express in the socketIOSample directory and save it in the dependencies list with following command:
Now, we need to install Socket.IO library. To do this, enter the following commands:
After all library installed. We have 2 files; server side named index.js and the other one is client-side named index.html.
Server-side sample code and containing the following contents:
Client-side sample code and containing the following contents:
In this application, our main focus is to establish a connection between the client-side and server-side with Socket.IO and show the message we read from the client-side and send it back to the client-side.
With the command below, we connect to the client-side and when the data message is received, we listen to the incoming message and send the same message to the client-side with the emit command.
Now run our basic socket.IO app server using the following command and type:
“http://127.0.0.1:3000“ in any browser, the outputs will be as follow:
Thank you for reading our blog post.