Registry / http-networking / rsocket-tcp-server

rsocket-tcp-server

JSON →
library0.0.29-alpha.0jsnpmunverified

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-server
INSTALL
IMPORT
SIG · RSOCKET-TCP-SERVER
R
rsocket-tcp-server
http-networkingjavascriptv0.0.29-alpha.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RSocketServer
import { RSocketServer } from 'rsocket-core';
const RSocketServer = require('rsocket-core');
Main server class, imported from `rsocket-core`. The `rsocket-js` monorepo targets ESM, so `require` is generally incorrect for newer versions and TypeScript.
TcpServerTransport
import { TcpServerTransport } from 'rsocket-tcp-server';
const TcpServerTransport = require('rsocket-tcp-server');
Specific transport implementation for TCP connections. Part of the `rsocket-js` monorepo's ESM-first approach.
Flowable, Single, Payload
import { Flowable, Single, Payload } from 'rsocket-flowable';
import { Flowable, Single } from 'rsocket-core';
These types are used for defining handlers for different RSocket interaction models (e.g., requestStream, requestResponse). While `Payload` is conceptually core, the Reactive Streams implementations like `Flowable` and `Single` are typically found in `rsocket-flowable`.

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.

import { RSocketServer, Payload } from 'rsocket-core'; import { TcpServerTransport } from 'rsocket-tcp-server'; import { Flowable, Single } from 'rsocket-flowable'; const port = 9000; // Define a request handler for the RSocket server const getRequestHandler = ( socket: any, // RSocket instance representing the client connection setupPayload: Payload // Initial payload sent during connection setup ) => { console.log('Client connected:', setupPayload.data?.toString()); return { requestResponse: (payload: Payload): Single<Payload> => { console.log('Received Request-Response:', payload.data?.toString()); return new Single(subscriber => { if (payload.data) { const responseData = `Echo: ${payload.data.toString()}`; subscriber.onComplete({ data: Buffer.from(responseData), metadata: payload.metadata, }); } else { subscriber.onError(new Error('No data in payload')); } }); }, requestStream: (payload: Payload): Flowable<Payload> => { console.log('Received Request-Stream:', payload.data?.toString()); return new Flowable(subscriber => { let count = 0; const interval = setInterval(() => { if (count < 5) { subscriber.onNext({ data: Buffer.from(`Stream ${count++}: ${payload.data?.toString()}`), metadata: payload.metadata, }); } else { clearInterval(interval); subscriber.onComplete(); } }, 1000); return { cancel: () => { console.log('Stream cancelled by client'); clearInterval(interval); }, onComplete: () => { console.log('Stream completed by client'); clearInterval(interval); } }; }); }, // Add other interaction models like fireAndForget, requestChannel as needed }; }; async function startServer() { const server = new RSocketServer({ transport: new TcpServerTransport({ address: '127.0.0.1', port }), getRequestHandler: getRequestHandler, // Setup common serializers for JSON if needed // serializers: JsonSerializers, // For 0.x versions, ensure mime types are compatible setup: { dataMimeType: 'text/plain', metadataMimeType: 'text/plain', keepAlive: 60000, // 60 seconds lifetime: 180000, // 3 minutes }, }); try { await server.bind(); console.log(`RSocket TCP server listening on port ${port}`); } catch (error) { console.error('Failed to start RSocket TCP server:', error); process.exit(1); } } startServer(); // Example: Graceful shutdown process.on('SIGINT', async () => { console.log('Shutting down server...'); // Await server.close() if available in your RSocketServer version process.exit(0); });
Debug
Known issues
breakingThe `rsocket-js` monorepo, including `rsocket-tcp-server`, is in active development with `0.x.x` and `1.0.0-alpha.x` versions. The `1.0.0-alpha.x` branch represents a significant rewrite to TypeScript, making it unstable and subject to breaking API changes without adhering to strict semantic versioning practices, particularly between alpha releases. Mixing `0.x.x` and `1.0.0-alpha.x` packages is explicitly discouraged and will likely lead to compatibility issues.
fix
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`).
affects: >=0.0.1-alpha
gotchaRSocket relies heavily on MIME types for data and metadata negotiation. Incorrectly configured `dataMimeType` or `metadataMimeType` in the `setup` payload can lead to deserialization errors or an inability for the server to route requests correctly, especially when interacting with clients implemented in different languages or frameworks.
fix
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`.
affects: >=0.0.1-alpha
gotchaHandling back-pressure and stream cancellation correctly in `requestStream` and `requestChannel` handlers is crucial. If a client cancels a stream, the server-side `Flowable` should clean up resources (e.g., `setInterval`) to prevent memory leaks or unnecessary processing. Similarly, the server needs to respect client demand signals (e.g., `subscriber.request(n)`).
fix
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.
affects: >=0.0.1-alpha
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'connect')
Attempting to call `connect()` on `RSocketServer` (which uses `bind()`) or on an incorrectly initialized client. Or, trying to `new RSocketServer()` without the `new` keyword.
fix
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.
Error: Destination '' does not support REQUEST_CHANNEL. Supported interaction(s): [METADATA_PUSH, SETUP]
The client is sending a request with a routing metadata, but the server's `getRequestHandler` does not have a corresponding handler for the specified route or interaction model. This often happens with an empty or unexpected routing string.
fix
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.
RSocketClient: Connection closed. (or similar generic connection error)
A generic error indicating that the RSocket connection failed or was terminated without a more specific application-level error. This can stem from various low-level issues: port conflicts, network problems, invalid setup payloads, or unhandled errors on either client or server.
fix
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.
Upgrade
Version history
0.0.29-alpha.0latest on npm
Audit
Dependencies
rsocket-corerequiredProvides the fundamental RSocket protocol implementation and core server abstractions like RSocketServer.
rsocket-flowablerequiredOffers Reactive Streams compliant types (Flowable, Single) used in RSocket handler implementations.
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
rsocket-tcp-server — npm install rsocket-tcp-server · libregistry