tcp-emitter-client

阅读时长 8 分钟读完

Client for TCP Emitter Server

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

API

require('tcp-emitter-client')(options)

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

client.socket

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

client.connect(..)

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

Alias to client.socket.connect.

client.end(..)

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.
  • 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

-- -------------------- ---- -------
-- ------ - --- --- ------- -------
----- ---------- - -------------------------------

-- -------- -- ----- -- - -------- --- ---- --------
----- -------- - ------ -- ------------------ ---------

-- ---- ------ - -------- -- -- ----- ------ ---------- -- - --- ------- -------
-- --- ------- ------ ---- -------- -- - ------ ------------ --- ---- -------
-- ---- ------- - --- ------- --------- --------
------------------------- ---------

-- ---- ---------- -- - --- ------- ------- --- ------- ------ ---- --------- --
-- --- --- ------ -- --------- --- ----------- -- ----- ---- --- --------- ----
-- -- ------- ---- - --------- ------ ----- --- ---- -------
------------------------

-- ---- ------ --- ----- -------- -- -- ----- -- --- ------- ------ -----
-- ---------- -- - --- ------- ------- --- ------- ------ ---- -------------
-- ---- - --- ------- --------- ------- -- --- --- ------- ------ -- --
-- --------- --- -- ----- ---- --- -------- - ------ --------- -- --- ----- ----
-- -- ------- -------- - --------- ------ ----- --- ---- ------
---------------------------- ---------

-- ---- -------- --- ---- -------- ---- - --- ------- ------ ----- ---------- --
-- - --- ------- ------- --- ------- ------ ---- ------------- ---- - ---
-- ------- ----------- ------- -- --- --- ------- ------ -- -- --------- ---
---------------------------------------- ---------

-- ---- -------- -- ----- ----- ---------- --- --- ------- ------ -- - ---
-- ------- ------- --- ------- ------ ---- ------------- ---- - --- -------
-- --------- ------- -- --- --- ------- ------ -- -- --------- --- -- ----- ----
-- -- ---- ------ --- --------- -- --- ----- ------- -- --- --- ----- ---------
-- --------
--------------------------- --- ---- ----- - ----- ------ ---

Tests

Generate Documentation

License

ISC

HomePage

https://github.com/tcp-emitter/node-client#readme

Repository

git+https://github.com/tcp-emitter/node-client.git

来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/6005606d81e8991b448de930

纠错
反馈