Skip to content

Server Specifications

GiZano edited this page Jan 23, 2026 · 1 revision

Server Specifications & Protocol

This document defines the strict communication standards required to interact with the Central Server. All client implementations must adhere to these rules to ensure interoperability.

1. Network Configuration

  • Transport Layer: TCP/IP
  • Default Port: 65432
  • Bind Address: 0.0.0.0 (The server listens on all network interfaces).
  • Encoding: UTF-8

2. The JSON Standard (Strict)

The server parses incoming byte streams as JSON objects. Every message—without exception—must conform to the following schema.

Message Schema

{
  "from": {
    "name": "SenderUsername",
    "ip": "SenderIP"
  },
  "to": "RecipientUsername",
  "msg": "Text Payload"
}

Field Definitions

Field Type Description
from Object Container for sender details.
from.name String Unique identifier chosen by the user.
from.ip String The local IP address of the sender (for logging).
to String Exact username of the recipient.
msg String The actual message content.

Critical: Messages that do not contain these exact keys will be discarded by the server's try-except block in the JSON decoder.

3. Connection Lifecycle

Phase A: Handshake

Upon establishing a TCP connection, the client must immediately send its Username as raw bytes (encoded in UTF-8).

  • Action: Client sends b'MyName'.
  • Server Logic: Registers the socket in the internal clients dictionary map.

Phase B: Messaging

The client enters a loop sending JSON-formatted strings.

  • Server Logic: Decodes JSON -> Extracts to field -> Looks up destination socket -> Forwards the original JSON packet to the recipient.

Phase C: Disconnection

When a client closes the socket:

  • Server Logic: Detects empty byte stream -> Removes user from clients map -> Logs disconnection.

4. Special Commands (Debug)

  • /standard: If the payload msg equals /standard, the server will reply directly to the sender with a confirmation message, verifying that the JSON structure was parsed correctly.

🔙 Back to Home

Clone this wiki locally