test-socket-server

Test socket server that sends back variable framed random data

test-socket-server

A framing socket server for testing clients. Still a work-in-progress since i'll be adding to this as needed to test client functionality.

It expects the data to be sent in the following format:

frame_sizerpc iddata
44ignored

And returns random data between 100 and 2048 bytes in the following format:

frame_sizerpc idrandom data
44100-2048

Data is sent in Big-endian.

Instantiate the TestSocketServer with some parameters to control how it behaves:

var TestSocketServer = require('test-socket-server');
 
// use defaults 
var server = new TestSocketServer();
 
// or set some specific behavior so the server gets "stuck" before it sends a response 
// as stays stuck for 10000ms. 
var server = new TestSocketServer({
    stuck_ms: 10000,
    stuck_before_response: true
});
 
// connect to it.... 
 

The default options are:

{
    timeout_ms: 60000,
    stuck_ms: 30000,
    stuck_before_response: false,
    stuck_partial_response: false,
    stuck_action: null
}

And the explanation for each parameter:

timeout_ms: Main socket timeout. If no activity occurs on a socket for this time, it will close the connection.

stuck_ms: Amount of time to stay "stuck" if one of the stuck situations is enabled

stuck_before_response: Server will stop sending data (stuck) after receiving a request and before a response is sent for stuck_ms. This does not drop the connection until the timeout_ms passes or the client ends the connection.

stuck_partial_response: Server will stop sending data (stuck) after receiving a request and after partial response data is sent for stuck_ms. This does not drop the connection until the timeout_ms passes or the client ends the connection.

stuck_action: A function to call when the server gets "stuck". By default (null) it does nothing but wait till the stuck_ms expires. Note that the stuck_ms timeout is still in effect even if an action is provided. It is passed the connection object as a parameter.

npm install test-socket-server

Use this to run some basic functional tests:

npm test

MIT License