0.2.0 • Published 1 year ago

moleculer-tcp v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Moleculer logo

This Moleculer Service mixin provides a tcp gateway. Incoming data from the connection is processed by the handleData action. Override this action with your own implementation. Connections all have a unique id and their own data store which can be utilized to store arbitrary data for the connection.

Settings

PropertyTypeDefaultDescription
portnumber2323Port number to listen. This setting can also be set by theMOLECULER_TELNET_HOST environment variable
hoststring127.0.0.1Hostname to listen. This setting can also be set by theMOLECULER_TELNET_HOST environment variable
tlsobject (see NodeJS TLS OptionsnullTLS options.
maxConnectionsnumbernullMaximum number of connections.
emitDatabooleanfalseEmittcp.data event when a new data received.
timeoutnumbernullTimeout in milliseconds.

Actions

NameParametersVisibilityDescription
handleDatadata: stringprivateThis action is called when a new data received from the connection.
getConnectionDataconnectionId: string, key: stringpublicGets data from the connection's data store.
setConnectionDataconnectionId: string, key: string, value: anypublicSets data to the connection's data store.
deleteConnectionDataconnectionId: string, key: stringpublicDeletes data from the connection's data store.
sendconnectionId: string, data: stringpublicSends data to the connection.

Events

NameParametersDescription
tcp.connectionid: stringemitted when a client has connected.
tcp.listening*emitted when the server has been bound
tcp.closeemitted when the server closes. If connections exist, this event is not emitted until all connections are ended.
tcp.droplocalAddress: string, localPort: number, remoteAddress: string, remotePort: numberemitted when the number of connections reaches the threshold of settings.maxConnections, the server will drop new connections and emit drop event instead.
tcp.socket.dataid: string, data: stringemitted when a client sends data. This is ONLY emitted if settings.emitData is set to true.
tcp.socket.closeid: stringemitted when a client closes the connection.
tcp.socket.errorid: string, error: Erroremitted when a client has an error.
tcp.socket.timeoutid: stringemitted when a client has a timeout.