Options
All
  • Public
  • Public/Protected
  • All
V1.7
  • V1.6
  • V1.7
Menu

Class Tcp

TCP handles are used to represent both TCP streams and servers.

Wrapper for uv_tcp_t. See http://docs.libuv.org/en/v1.x/tcp.html

Hierarchy

Index

Constructors

constructor

  • new Tcp(): Tcp

Properties

peername

peername: Address

Readable property exposing the address of the peer connected to the handle.

Wraps uv_tcp_getpeername.

sockname

sockname: Address

Readable property exposing the current address to which the handle is bound

Wraps uv_tcp_getsockname.

Methods

accept

  • accept(client: Stream): void
  • This call is used in conjunction with Stream.listen to accept incoming connections. Call this function after receiving a connection callback to accept the connection.

    Wraps uv_accept.

    Parameters

    Returns void

bind

  • bind(ip: string, port: number): void
  • Bind the handle to an address and port.

    Wraps uv_tcp_bind.

    Parameters

    • ip: string
    • port: number

    Returns void

close

  • close(onClose?: () => void): void
  • Request handle to be closed.

    Wrapper for uv_close.

    Parameters

    • Optional onClose: () => void
        • (): void
        • Returns void

    Returns void

connect

  • connect(req: Connect, ip: string, port: number, onConnect: (error: Error) => void): void
  • Establish an IPv4 or IPv6 TCP connection.

    Wraps uv_tcp_connect.

    Parameters

    • req: Connect
    • ip: string
    • port: number
    • onConnect: (error: Error) => void
        • (error: Error): void
        • Parameters

          • error: Error

          Returns void

    Returns void

hasRef

  • hasRef(): boolean
  • Returns true if the handle referenced, false otherwise.

    Wrapper for uv_has_ref.

    Returns boolean

listen

  • listen(backlog: number, onConnection: (error: Error) => void): void
  • Start listening for incoming connections.

    server.listen(backlog, (error) => {
      ...
      const client = new Tcp();
      server.accept(client)
      ...
    });

    Wraps uv_listen.

    Parameters

    • backlog: number

      indicates the number of connections the kernel might queue.

    • onConnection: (error: Error) => void

      is called when a new incoming connection is received.

        • (error: Error): void
        • Parameters

          • error: Error

          Returns void

    Returns void

readStart

  • readStart(onRead: (error: Error, data?: ArrayBuffer) => void): void
  • Read data from an incoming stream.

    Parameters

    • onRead: (error: Error, data?: ArrayBuffer) => void

      will be called several times until there is no more data to read or Stream.readStop is called.

      Wraps uv_read_start.

        • (error: Error, data?: ArrayBuffer): void
        • Parameters

          • error: Error
          • Optional data: ArrayBuffer

          Returns void

    Returns void

readStop

  • readStop(): void

ref

  • ref(): void

shutdown

  • shutdown(req: Shutdown, onShutdown: (error: Error) => void): void
  • Shutdown the outgoing (write) side of a duplex stream.

    Wraps uv_shutdown.

    Parameters

    • req: Shutdown
    • onShutdown: (error: Error) => void
        • (error: Error): void
        • Parameters

          • error: Error

          Returns void

    Returns void

unref

  • unref(): void

write

  • write(req: Write, data: ArrayBufferView | ArrayBuffer, onWrite: (error: Error) => void): void
  • Write data to stream. Buffers are written in order.

    stream.write(new Write(), data, (error) => {
      print('The data was written...');
    });

    Wraps uv_write.

    Parameters

    • req: Write
    • data: ArrayBufferView | ArrayBuffer
    • onWrite: (error: Error) => void
        • (error: Error): void
        • Parameters

          • error: Error

          Returns void

    Returns void

Generated using TypeDoc