Skip to content

arshitcc/AK-SCS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

AlgoKart - Socket Chat Server (Assignment)

A simple TCP chat app built with Node.js (no other runtime or packages required).

What's included in this project:

  • User login (LOGIN <username>) and broadcast messaging (MSG <text>).
  • Direct messages (DM <username> <text>) and list active users (WHO).
  • Idle timeout: the server disconnects clients after 60 seconds of inactivity.

Demo

Requirements

  • Node.js (v22+ recommended)

Files

  • server.js — server implementation
  • client.js — client implementation

How to run

Start the server in one terminal:

node server.js

Start a client (open another terminal per client):

node client.js

Default port: 4000. You can set PORT environment variable for the server if you want a different port.


Commands (client → server)

  • LOGIN <username> — log in with a username
  • MSG <text> — broadcast message to all other users
  • DM <username> <text> — send private message to username
  • WHO — list other active users
  • exit or EXIT — quit the client

Heartbeat/idle behaviour:

  • If no activity from client for 60 seconds, server will send INFO idle-timeout and close the connection.

Examples

1) LOGIN one

Client input:

LOGIN alice

Server response (to that client):

OK

2) DM one

Alice wants to DM Bob: Client (Alice) input:

DM bob Hey Bob — are you there?

If Bob is online, Bob receives:

DM FROM alice Hey Bob — are you there?

3) LIST Active users

Client input:

WHO

Client receives one line per other user, e.g.:

USER bob
USER charlie

Sample session (2 terminals)

Terminal A (server):

$ node server.js
Server is running on PORT : 4000
> INFO alice connected
> INFO bob connected
> INFO alice disconnected (idle-timeout)

Terminal B (client: alice):

> LOGIN alice
OK
> MSG Hello everyone
> DM bob Hi Bob
> WHO
> USER bob
> USER charlie

Terminal C (client: bob):

> LOGIN bob
OK
MSG alice Hello everyone
DM FROM alice Hi Bob

Note

  • Idle timeout and intervals are configurable in the code as constants:

    • IDLE_TIMEOUT_MS (server) — default 60_000 (60s)
    • IDLE_CHECK_INTERVAL_MS (server) — default 10_000 (10s)

About

a simple TCP chat server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published