Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Tcp<EventTypes>

Create a TCP connection from a device throught the network the device is currently connected to.

Type parameters

  • EventTypes: string

Hierarchy

Index

Constructors

constructor

  • new Tcp(obniz: Obniz, id: number): Tcp

Properties

Obniz

Obniz: Obniz

obniz to be used

Optional onconnection

Callback function is called when there is a change in TCP connection status.

// Javascript Example
var tcp = obniz.getFreeTcp();

tcp.onconnection = data => {
 console.log(data);
};
tcp.connectWait(80,"obniz.io");

Optional onerror

You can get the error message that occurred when connecting.

// Javascript Example
var tcp = obniz.getFreeTcp();
tcp.connectWait(80,"obniz.io");

tcp.onerror = state => {
  console.log(state);
};

Optional onreceive

Callback function is called when TCP is received.

// Javascript Example
var tcp = obniz.getFreeTcp();
tcp.connectWait(80,"obniz.io");

tcp.onreceive = data => {
  console.log(data);
};

timeout

timeout: number = 30 * 1000

Rsponse waiting timeout in milliseconds

Static prefixed

prefixed: string | boolean

Methods

addListener

  • addListener(event: EventTypes, fn: ListenerFn, context?: any): this

connectWait

  • connectWait(port: number, domain: string): Promise<void>
  • Starts a connection on the port and domain for which TCP is specified.

    // Javascript Example
    var tcp = obniz.getFreeTcp();
    tcp.connectWait(80,"obniz.io");

    Parameters

    • port: number
    • domain: string

    Returns Promise<void>

emit

  • emit(event: EventTypes, ...args: Array<any>): boolean
  • Calls each of the listeners registered for a given event.

    Parameters

    • event: EventTypes
    • Rest ...args: Array<any>

    Returns boolean

end

  • end(): void
  • Terminates the TCP session.

    // Javascript Example
    var tcp = obniz.getFreeTcp();
    tcp.end();

    Returns void

eventNames

  • eventNames(): Array<EventTypes>
  • Return an array listing the events for which the emitter has registered listeners.

    Returns Array<EventTypes>

fastValidate

  • fastValidate(commandUri: any, json: any): boolean
  • Parameters

    • commandUri: any
    • json: any

    Returns boolean

listenerCount

  • listenerCount(event: EventTypes): number
  • Return the number of listeners listening to a given event.

    Parameters

    • event: EventTypes

    Returns number

listeners

  • Return the listeners registered for a given event.

    Parameters

    • event: EventTypes

    Returns Array<ListenerFn>

notifyFromObniz

  • notifyFromObniz(json: any): void

off

  • off(event: EventTypes, fn?: EventEmitter.ListenerFn, context?: any, once?: undefined | false | true): this
  • Parameters

    • event: EventTypes
    • Optional fn: EventEmitter.ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

on

  • on(event: EventTypes, fn: ListenerFn, context?: any): this
  • Add a listener for a given event.

    Parameters

    • event: EventTypes
    • fn: ListenerFn
    • Optional context: any

    Returns this

once

  • once(event: EventTypes, fn: ListenerFn, context?: any): this
  • Add a one-time listener for a given event.

    Parameters

    • event: EventTypes
    • fn: ListenerFn
    • Optional context: any

    Returns this

readWait

  • readWait(): Promise<number[]>
  • Wait for TCP reception.

    // Javascript Example
    var tcp = obniz.getFreeTcp();
    tcp.connectWait(80,"obniz.io");
    
    let data = await tcp.readWait();
    console.log(data);

    Returns Promise<number[]>

removeAllListeners

removeListener

  • removeListener(event: EventTypes, fn?: EventEmitter.ListenerFn, context?: any, once?: undefined | false | true): this
  • Remove the listeners of a given event.

    Parameters

    • event: EventTypes
    • Optional fn: EventEmitter.ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

schemaBasePath

  • schemaBasePath(): string

validate

  • validate(commandUri: any, json: any): WSSchema.MultiResult
  • Parameters

    • commandUri: any
    • json: any

    Returns WSSchema.MultiResult

write

  • write(data: number | number[] | Buffer | string): void
  • The argument data is sent by TCP.

    If you pass a string or Array type argument, the data will be sent.

    // Javascript Example
    var tcp = obniz.getFreeTcp();
    tcp.connectWait(80,"obniz.io");
    
    // Array
    tcp.write([0,1,2,3,4]);
    
    // Text
    tcp.write('hello');

    Parameters

    • data: number | number[] | Buffer | string

    Returns void

Generated using TypeDoc