TCP Emitter NodeJS Client

TCP Emitter Client is an EventEmitter that can connect with a TCP Emitter Server to interact with other connected clients.

Installation

npm install --save tcp-emitter-client

API

Options Type Default Description options.delimiter string '@@@' Delimiter used to seperate payloads in a single TCP request. More info here.

net.Socket object used to connect the TCP Emitter client with the TCP Emitter server .

Function used to connect the TCP Emitter client with a TCP Emitter server .

Alias to client.socket.connect.

Function used to disconnect the TCP Emitter client from the TCP Emitter server .

Alias to client.socket.end.

TCP Emitter Requests

When a TCP Emitter client is connected to a TCP Emitter server , apart from functioning as a normal EventEmitter, it will need to interact with the TCP Emitter server it is connected to through TCP requests. The following section describes when this client sends each type of request.

Subscribe Request

When the TCP Emitter client connects with a TCP Emitter server it will subscribe to all the events it has registered listeners.

connects with a it will subscribe to all the events it has registered listeners. When the TCP Emitter client is connected to a TCP Emitter server and a first listener is added to an event.

Unsubscribe Request

When the TCP Emitter client is connected to a TCP Emitter server and a last listener is removed from an event.

Broadcast Request

When the TCP Emitter client is connected to a TCP Emitter server and an event is emitted.

Example

const clientInst = require ( ' tcp-emitter-client ' ) ( ) const listener = ( name ) => console . log ( ` Hello ${ name } ` ) clientInst . on ( ' new-user ' , listener ) clientInst . connect ( 8080 ) clientInst . on ( ' remove-user ' , listener ) clientInst . removeListener ( ' remove-user ' , listener ) clientInst . emit ( ' new-user ' , [ 1 , ' 2 ' , true , { name : ' luca ' } ] )

Tests

npm install npm test

Generate Documentation

npm install npm run docs

License

ISC