pcats-listener
TCP listener, provides message decoding and encoding using proprietary binary protocol.
Request processor function is injected into server to handle requests:
listener.createServer(processor)
Processor function will be called with decoded request String and expected to return the response String or response Promise. If no response should be sent, just return nothing or resolve promise with no value.
Also a Client is provided for testing and simulation.
Install:
npm install pcats-listener
Run Server:
var listener = ; /** * Request processor function is injected into server to handle requests. * * @param * @returns */{ // process the request and return response return "Hello " + request;} var server = listener; server;
Run Client:
var listener = ;var client = listener; client;
also see examples folder for more client implementations
Client Connection API:
-
connection.request(message, [callback])
sends request. connection will emit 'response' event when response is received. The optionalcallback
parameter will be executed when the data is finally written out - this may not be immediately -
connection.end()
request connection to close -
Event: 'response'
emits 'response' event when response is received -
Event: 'close'
emits 'close' event if tcp connection was closed before connection.end() was called