mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Allow partial responder in ClientConfig * add tests * move tests into client and server packages * Update TS version to 2.2
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { RSocketServer, BufferEncoders } from 'rsocket-core';
|
|
import RSocketTCPServer from 'rsocket-tcp-server';
|
|
import { Payload } from 'rsocket-types';
|
|
import { Single } from 'rsocket-flowable';
|
|
|
|
const HOST = process.env.HOST || '127.0.0.1';
|
|
const PORT = process.env.PORT || '8080';
|
|
|
|
// Create an instance of a client
|
|
const server = new RSocketServer<Buffer, null> ({
|
|
// Handle incoming connections
|
|
getRequestHandler: (socket, payload) => {
|
|
console.log('connect payload', payload);
|
|
socket.connectionStatus().subscribe({
|
|
onNext: value => {
|
|
console.log('connection', value);
|
|
}
|
|
});
|
|
|
|
// Return a responder that handles incoming payloads
|
|
// We only handle the request/response type
|
|
return {
|
|
requestResponse: (incomingRequest: Payload<Buffer, null>) => {
|
|
console.log('->', incomingRequest);
|
|
// Echo the request back
|
|
return new Single(subscriber => {
|
|
subscriber.onSubscribe(() => {});
|
|
console.log('<-', incomingRequest);
|
|
subscriber.onComplete(incomingRequest);
|
|
});
|
|
},
|
|
};
|
|
},
|
|
|
|
// Transports default to sending/receiving strings:
|
|
// Use BufferEncoders to enable binary
|
|
transport: new RSocketTCPServer(
|
|
{ host: HOST, port: +PORT }, // options to Node.js net.connect()
|
|
BufferEncoders,
|
|
),
|
|
});
|
|
|
|
console.log('starting server...');
|
|
server.start();
|