Skip to content

backendbishop/echospace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Echospace

A real-time WebSocket chat server with named rooms and multi-client support. I wrote this code to understand how persistent connections work — how a server keeps multiple clients alive simultaneously, routes messages between them, and handles disconnects cleanly.

WebSocket keeps a persistent connection open between client and server. When a message comes in, the server parses it, looks up the room, iterates the connected clients, checks each connection is still open, and sends. The sender is excluded to prevent echo.

Message types

{ "type": "setName", "username": "simon" }
{ "type": "join", "room": "backend" }
{ "type": "message", "text": "hello" }

Responses

{ "type": "info", "message": "Joined room: backend" }
{ "type": "message", "from": "simon", "room": "backend", "text": "hello" }
{ "type": "error", "message": "Invalid message format" }

Run locally

npm install
node index.js

Connect with any WebSocket client on ws://localhost:3002

Stack

Node.js · Express · ws

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages