A deep analysis of Java class linking and the stateless virtual room model.
The RCWeb system is built on a streamlined, high-performance architecture centered around real-time communication between browsers. Below is a map of the primary Java classes and how they link together.
HttpHandlerCreated by the HttpServer for each incoming connection. It runs in its own virtual thread,
managing the lifecycle of an HTTP request. It parses the HttpRequest, delegates it to a
responder (e.g., RootResponder), and writes back the HttpResponse.
SuperSocketA wrapper around the standard Java Socket that provides enhanced capabilities, such as TLS
sniffing and connection lifecycle management.
HttpRequest & HttpResponseRepresent the standardized HTTP request and response models. HttpRequest is parsed from the
SuperSocket's input stream, while HttpResponse is generated by the responder and
written back over the network.
RoomManagerA singleton service that acts as the central registry for all active workspaces (Rooms). It maintains a
concurrent map of roomId strings to Room objects. It also runs a
background maintenance thread to prune inactive connections and cleanly close all sockets during JVM
shutdown.
RoomRepresents a virtual environment where multiple browsers can interact. A Room maintains a list
of attached Client objects. It provides the crucial broadcast() method, which
routes a ClientCommand (containing JavaScript payloads) to specific target clients within the
room.
ClientRepresents an active browser connection within a Room. It holds a ClientRequest containing
metadata (IP, user-agent, timers) and a thread-safe queue of ClientCommand objects. Virtual
threads waiting for outgoing WebSocket traffic synchronize on this object via wait() and
notifyAll().
ClientWebSocketHandlerUpgrades the HTTP request and handles the active WebSocket lifecycle. It runs an infinite loop within a
virtual thread, blocking on client.wait(IDLE_PERIOD) until a new command is queued. When data
is received from the browser, it reads the raw byte array, parses it into a ClientCommand, and
dispatches it via room.broadcast().
ClientCommandA lightweight wrapper representing a message to be sent to browsers. It encapsulates target identifiers (which browsers should receive this) and the raw byte payload of the JavaScript to be executed on the client-side.
A fundamental concept of the RCWeb architecture is the Virtual Room. Rather than each
browser maintaining an isolated session with the server, browsers connect to a shared Room
using a unique ID in their URL.
The server acts purely as a message broker. When an event happens in one browser (e.g., a user clicks a
button or moves a slider), it sends a WebSocket message containing executable JavaScript. The backend
ClientWebSocketHandler catches this, wraps it in a ClientCommand, and asks the
Room to broadcast it.
The Room forwards this JavaScript payload into the command queues of other relevant
Clients in the same room. The server pushes this JavaScript down their WebSockets, and the
receiving browsers execute it immediately using eval() or script injection. This allows
browsers to seamlessly share state and replicate user interfaces in real-time.
RCWeb embraces a heavily stateless backend design.
Client objects and a few bytes for the
ClientCommand queues. Instead of consuming expensive OS threads for each WebSocket connection,
ClientWebSocketHandler leverages Java Virtual Threads. Handlers simply call
client.wait(), consuming virtually no resources while waiting for traffic. This architecture
allows a single small instance to effortlessly handle thousands of concurrent, real-time web socket
connections.