Client and Server programs for testing socket communication.
For development, you will only need Node.js and a node global package, installed in your environement.
-
Just go on official Node.js website and download the installer.
-
You can install NodeJs and npm with apt install, using the following commands:
$ sudo apt install nodejs $ sudo apt install npm
-
You can find more information about the installation on the official Node.js website and the official NPM website.
If the installation was successful, you should be able to run the following command from your command line:
$ node --version
$ npm --version
$ npm install socket.io
$ npm install socket.io-client
$ git clone https://github.com/brworkit/socket-node-example.git
$ cd socket-node-example
Start server using:
$ npm start server
Start client using (in another bash):
$ node client.js
You will see in your client prompt the current time from Javascript Date class in ISO format:
{ time: time ISO format }
You you see in your server prompt:
client <client id> connected <time ISO format>.
MIT License.
Copyright (c) 2020 brworkit.