Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TcpSocket

Tcp socket wrapper with package compositing. Collect the package from socket and emit a completed package with 'data' event. Uniform with ws.WebSocket interfaces.

param

origin socket from node.js net module

param

options parameter. opts.headSize size of package head opts.headHandler(headBuffer) handler for package head. caculate and return body size from head data.

Hierarchy

  • Stream
    • TcpSocket

Implements

Index

Constructors

constructor

Properties

_socket

_socket: Socket

closeMethod

closeMethod: string

headBuffer

headBuffer: Buffer

headHandler

headHandler: Function

headOffset

headOffset: number

headSize

headSize: number

packageBuffer

packageBuffer: Buffer

packageOffset

packageOffset: number

packageSize

packageSize: number

readable

readable: boolean

state

state: number

writeable

writeable: boolean

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

close

  • close(): void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number
  • Returns number

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

ondata

  • ondata(chunk: Buffer): boolean

onend

  • onend(chunk: Buffer): void

pipe

  • pipe<T>(destination: T, options?: object): T
  • Type parameters

    • T: WritableStream

    Parameters

    • destination: T
    • Optional options: object
      • Optional end?: boolean

    Returns T

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

readBody

  • readBody(data: Buffer, offset: number): number
  • Read body segment from data buffer to socket.packageBuffer;

    Parameters

    • data: Buffer

      Buffer instance

    • offset: number

      offset read star from data

    Returns number

    new offset of data after read

readHead

  • readHead(data: Buffer, offset: number): number
  • Read head segment from data to socket.headBuffer.

    Parameters

    • data: Buffer

      Buffer instance

    • offset: number

      offset read star from data

    Returns number

    new offset of data after read

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

reset

  • reset(): void

send

  • send(msg: any, options: object, cb?: function): void
  • Parameters

    • msg: any
    • options: object
      • Optional binary?: boolean
    • Optional cb: function
        • (err?: Error): void
        • Parameters

          • Optional err: Error

          Returns void

    Returns void

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number