The `rsocket-tcp-server` package provides a TCP server implementation for the RSocket protocol within the `rsocket-js` monorepo. It enables applications to establish and manage RSocket connections over TCP, facilitating reactive, multiplexed, and high-performance communication. Currently, this specific package is at version `0.0.29-alpha.0`, reflecting its alpha development status. The broader `rsocket-js` project, which includes core RSocket functionalities, RxJS adapters, and GraphQL links, is also undergoing significant changes with `1.0.0-alpha.x` versions, including a rewrite to TypeScript from Flow. The project maintains an active development cadence, with frequent alpha releases across its constituent packages. Its primary differentiation lies in offering a native JavaScript/TypeScript implementation of the RSocket protocol, a critical component for building responsive microservices and real-time data streaming architectures in Node.js environments.
npm install rsocket-tcp-serverVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up an RSocket TCP server that listens on a specified port and handles basic request-response and request-stream interactions, echoing received data.
Always pin exact versions of `rsocket-js` packages during alpha development. Refer to the specific `rsocket.io` guides for the version you are using (0.x vs 1.0.0-alpha). Ensure all related `rsocket-*` packages in your project are of compatible versions (e.g., all `0.x.x` or all `1.0.0-alpha.x`).
Explicitly set `dataMimeType` and `metadataMimeType` in the `RSocketServer` constructor options to match what the connecting clients are expected to send. Common choices include 'text/plain', 'application/json', or 'message/x.rsocket.routing.v0' for routing. For JSON, consider using `JsonSerializers` from `rsocket-core`.
Implement the `cancel` and `onComplete` methods within the `Flowable` return from your stream handlers to properly manage resources. Monitor client demand and generate payloads accordingly to avoid overwhelming the client or sending data that won't be consumed.
Ensure `RSocketServer` is instantiated correctly with `new RSocketServer(...)`. If it's a client attempting to connect, ensure you are using `RSocketConnector` or `RSocketClient` with a transport like `TcpClientTransport` for client-side connections, and that `connect()` is called on the client instance.
Verify that the `metadataMimeType` is correctly set (e.g., 'message/x.rsocket.routing.v0') and that the client is sending valid routing metadata. On the server, ensure `getRequestHandler` returns an object with methods matching the interaction models (e.g., `requestResponse`, `requestStream`, `requestChannel`) that the client is trying to invoke, and that any routing logic within those handlers correctly processes the metadata.
Enable debug logging on both client and server (if available in your `rsocket-js` version) to get more detailed insights into the connection negotiation and any frame errors. Check for port availability, network reachability, and ensure the `setup` payload's `keepAlive`, `lifetime`, and MIME types are correctly configured and compatible between client and server. Inspect server logs for unhandled exceptions in request handlers.