Skip to content

jordicenzano/websocket-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

websocket-chat

This is a simple POC that shows how to broadcast "instant" messages across browsers / clients using WebSockets and avoiding any polling. The goal of building this POC was just test WebSockets and increase the knowledge about this technology.

Block diagram

Gif example

Installation

  1. Install NodeJS (version 12+), we recommend doing that using NVM
  2. Install typescript utils (recommended globally)
npm install -g ts-node
npm install -g typescript
  1. Clone this repo:
git clone git@github.com:jordicenzano/websocket-chat.git
  1. Install packages
cd server
npm install
cd ..
  1. (ONLY if you want to use the secure version)Create self signed certificate and key running:
cd server/scripts
./createSelfSignedCert.sh
cd ../..

Test it

  1. Start the backend webSocket server code in a place where the clients can reach, for instance:
ts-node ./server/src/ws-chat-server.ts -p 8080

The previous command will run the server in your computer on port 8080

  1. Load this webpage in your device WebSocketChat

  2. Type ws://localhost:8080 (OR your server location) as WS Server URL (*)

  3. Type myroom (OR the room name you want) in Room ID

  4. Type RANDOM (OR the ID you want) in Name

  5. Press the "Connect" button

  6. Repeat steps 2 to 6 with as many clients as you want

  7. Send a messages

Tested with Chrome in MACOS.

(*) Some browsers (like Safari) can throw an error if you try to connect an NON encrypted WebSocket (ws:) from a HTTPS page.

Releases

No releases published

Packages

No packages published