Live Chat Server Example with Pure Websockets, Multiple lightweight container node servers with docker, Redis (Pub & Sub) & Load Balancing with Nginx
-
Make sure have been already installed docker & docker-compose in your OS (Mac OS / Linux / Windows).
-
You can build your own images :
docker build -t <yourusername/yourimagename>:addyourtag .
And change image src ("lb" service section) in
docker-compose.yml
configuration with your images.Or you can pull from my images hosted in Docker Hub :
docker pull pickezdocker/ws_live_chat_server:0.1
-
Run Commands :
docker-compose up
add
-d
parameter if want to running on background.Reverse Proxy will run in port
8080
- Spin up 2 or more window / tab browsers
- Then create new
Websocket
instances each browser with ex.Javascript
code :
// Initialize web socket instance
const webSocket = new WebSocket("ws://localhost:8080")
// Create "onmessage" events
webSocket.onmessage = (message)= > console.log(`You receive the messages : ${message.data}`)
// Try to send a message
webSocket.send("<yourmessagehere>")
- Try to send message each other