https://github.com/realabbas/websocket-example
Short WebSocket Example for mutating a global variable available throughout the connection 🔗
https://github.com/realabbas/websocket-example
client mutation nodejs server variable websocket ws
Last synced: 8 days ago
JSON representation
Short WebSocket Example for mutating a global variable available throughout the connection 🔗
- Host: GitHub
- URL: https://github.com/realabbas/websocket-example
- Owner: realabbas
- Created: 2021-04-05T11:22:22.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-06T05:37:08.000Z (about 5 years ago)
- Last Synced: 2025-03-05T06:19:05.504Z (about 1 year ago)
- Topics: client, mutation, nodejs, server, variable, websocket, ws
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#### Websocket-Example in Node.js
**Entities connected**
- Client
- Server
The connection is established and data is transferred back and forth, no overhead in passage flow.
##### Deductions
A Global variable retains its value from the time of connection establishment till connection termination. This example achieves the above statement and check out the code for better understanding
Package used is `websocket`
##### Example
Here Server declares an array **[1,2,3,4,5]** and sends first element **(1)** to the Client and then on receiving the data from the server, the client does some processing like here in this case, multiplies the incoming data by **2**, hence **(1\*2) = (2)** and transmits back the result to the server to mutate the original array.
Hence, now the server receives the data from client (2) and then it mutates the array [**1**,2,3,4,5] => [**2**,2,3,4,5] and then returns the array as payload to the client side. **[2,2,3,4,5]**