Skip to content

Latest commit

 

History

History
134 lines (89 loc) · 4.64 KB

File metadata and controls

134 lines (89 loc) · 4.64 KB

Tutorial Nodejs Net Socket Server and Clients

With this tutorial you can create Net Communication client-client and server-clients with Nodejs.



🔖 Description

The net module provides an asynchronous network API for creating stream-based TCP or IPC servers (net.createServer()) and clients (net.createConnection()).

With this Tutorial you can create a Nodejs Net Server and communicate with severals Clients via Socket.

Official Documentation: NodeJS | API Net

📹 Video Demo

How to execute a Net Server and two Clients and how the Server send random message to all Clients.

Video

How to Execute a Net Server and two Clients and how a Client send random message via Server to others Clients.

Video

⛅️ Develop in the Cloud

You can run this project in Gitpod, a one-click online IDE for GitHub:

Open in Gitpod

📌 Methodologies and Guidelines

List of methodologies and tools used in this project for compliance with Quality Assurance Code (QAC)

✅ Prerequisites

In order to work with this project, your local environment must have at least the following versions:

  • Nodejs Version: 13.xx
  • NPM Version: 6.12.0

📐 How to work with this project

You have to do the following steps to be able to work with this project.

1️⃣ Install Nodejs Dependencies

To work with this project locally it is necessary to install the NPM dependencies.

# Install npm dependencies
$npm i

2️⃣ Run

You will find two demos, in the first one, the server emit messages from a "setInterval" function to all the clients subscribed by socket and in the second one a client emit with a "setInterval" function severals message to the server by socket and this is transmitted to the other clients.

To run the first demo you need to activate at least ONE Server type Emitter and ONE Client Receiver:

# Run Server for Emit Messages
$npm run start:first-demo:server-emitter

# Run Client for Receive Message
$npm run start:first-demo:client-receiver

To run the second demo you need to activate ONE Server Dispatcher, at least ONE Clients Emitter and Others Receivers:

# Run Server for Receive and Emit Messages
$npm run start:second-demo:server-dispatcher

# Run Client for Emit Messages
$npm run start:second-demo:client-emitter

# Run at least one Client for Receive Messages
$npm run start:second-demo:client-receiver

📂 Code scaffolding

/
├── assets 🌈               # Images Sources.
├── src 📦                  # Main App with Server and Client.
|   ├── first-demo          # Demo with broadcast demo server sending randoms message to all clients.
|   ├── second-demo         # Demo with a client sending random message via server to all other clients.
|   └── ...
└── ...

⛽️ Review and Update Dependences

For review and update all npm dependences of this project you need install in global npm package "npm-check-updates" npm module.

# Install and Run
$npm i -g npm-check-updates
$ncu

License

MIT

Happy Code

Created with JavaScript, lot of ❤️ and a few ☕️

This README.md file has been written keeping in mind