Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NetSocket

Represents a socket-like interface to a TCP connection on either the client or the server side.

Instances of this class are created on the client side by an NetClient when a connection to a server is made, or on the server side by a NetServer when a server accepts a connection.

It implements both and so it can be used with Pipe to pipe data with flow control.

Hierarchy

  • NetSocket

Implements

Index

Methods

applicationLayerProtocol

  • applicationLayerProtocol(): string
  • Returns string

close

  • Close the NetSocket and notify the handler when the operation completes.

    Returns PromiseLike<void>

  • Close the NetSocket and notify the handler when the operation completes.

    Parameters

    Returns void

closeHandler

  • closeHandler(handler: ((res: void) => void) | Handler<void> | null | undefined): NetSocket
  • Set a handler that will be called when the NetSocket is closed

    Parameters

    • handler: ((res: void) => void) | Handler<void> | null | undefined

    Returns NetSocket

drainHandler

  • drainHandler(handler: ((res: void) => void) | Handler<void> | null | undefined): NetSocket
  • Parameters

    • handler: ((res: void) => void) | Handler<void> | null | undefined

    Returns NetSocket

end

  • Same as but with an handler called when the operation completes

    Parameters

    Returns PromiseLike<void>

  • Same as but with an handler called when the operation completes

    Parameters

    Returns void

  • Calls {@link NetSocket#end}.

    Returns PromiseLike<void>

  • Calls {@link NetSocket#end}.

    Parameters

    Returns void

endHandler

  • endHandler(endHandler: ((res: void) => void) | Handler<void> | null | undefined): NetSocket
  • This handler might be called after the close handler when the socket is paused and there are still buffers to deliver.

    Parameters

    • endHandler: ((res: void) => void) | Handler<void> | null | undefined

    Returns NetSocket

exceptionHandler

  • Parameters

    Returns NetSocket

fetch

  • Parameters

    • amount: number

    Returns NetSocket

handler

  • Parameters

    Returns NetSocket

indicatedServerName

  • indicatedServerName(): string
  • Returns the SNI server name presented during the SSL handshake by the client.

    Returns string

isSsl

  • isSsl(): boolean
  • Returns boolean

localAddress

  • Returns SocketAddress

  • Like {@link NetSocket#localAddress} ()} but returns the server local address when real is true

    Parameters

    • real: boolean

    Returns SocketAddress

pause

  • Returns NetSocket

pipe

  • Pause this stream and return a to transfer the elements of this stream to a destination .

    The stream will be resumed when the pipe will be wired to a WriteStream.

    Returns Pipe<Buffer>

pipeTo

  • Pipe this ReadStream to the WriteStream.

    Elements emitted by this stream will be written to the write stream until this stream ends or fails.

    Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

    Parameters

    Returns PromiseLike<void>

  • Pipe this ReadStream to the WriteStream.

    Elements emitted by this stream will be written to the write stream until this stream ends or fails.

    Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

    Parameters

    Returns void

remoteAddress

  • Returns SocketAddress

  • Like {@link NetSocket#remoteAddress} but returns the proxy remote address when real is true

    Parameters

    • real: boolean

    Returns SocketAddress

resume

sendFile

  • sendFile(filename: string): PromiseLike<void>
  • sendFile(filename: string, resultHandler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): NetSocket
  • sendFile(filename: string, offset: number): PromiseLike<void>
  • sendFile(filename: string, offset: number, resultHandler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): NetSocket
  • sendFile(filename: string, offset: number, length: number): PromiseLike<void>
  • sendFile(filename: string, offset: number, length: number, resultHandler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): NetSocket
  • Same as {@link NetSocket#sendFile} but also takes a handler that will be called when the send has completed or a failure has occurred

    Parameters

    • filename: string

    Returns PromiseLike<void>

  • Same as {@link NetSocket#sendFile} but also takes a handler that will be called when the send has completed or a failure has occurred

    Parameters

    Returns NetSocket

  • Same as {@link NetSocket#sendFile} but also takes a handler that will be called when the send has completed or a failure has occurred

    Parameters

    • filename: string
    • offset: number

    Returns PromiseLike<void>

  • Same as {@link NetSocket#sendFile} but also takes a handler that will be called when the send has completed or a failure has occurred

    Parameters

    Returns NetSocket

  • Same as {@link NetSocket#sendFile} but also takes a handler that will be called when the send has completed or a failure has occurred

    Parameters

    • filename: string
    • offset: number
    • length: number

    Returns PromiseLike<void>

  • Same as {@link NetSocket#sendFile} but also takes a handler that will be called when the send has completed or a failure has occurred

    Parameters

    Returns NetSocket

setWriteQueueMaxSize

  • setWriteQueueMaxSize(maxSize: number): NetSocket

sslSession

  • sslSession(): any
  • Returns any

upgradeToSsl

  • Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.

    Returns PromiseLike<void>

  • Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.

    Parameters

    Returns NetSocket

  • Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.

    Parameters

    • serverName: string

    Returns PromiseLike<void>

  • Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.

    Parameters

    Returns NetSocket

write

  • Same as {@link NetSocket#write} but with an handler called when the operation completes

    Parameters

    • str: string

    Returns PromiseLike<void>

  • Same as {@link NetSocket#write} but with an handler called when the operation completes

    Parameters

    Returns void

  • Same as {@link NetSocket#write} but with an handler called when the operation completes

    Parameters

    • str: string
    • enc: string

    Returns PromiseLike<void>

  • Same as {@link NetSocket#write} but with an handler called when the operation completes

    Parameters

    Returns void

  • Like {@link WriteStream#write} but with an handler called when the message has been written or failed to be written.

    Parameters

    Returns PromiseLike<void>

  • Like {@link WriteStream#write} but with an handler called when the message has been written or failed to be written.

    Parameters

    Returns void

writeHandlerID

  • writeHandlerID(): string
  • When a NetSocket is created, it may register an event handler with the event bus, the ID of that handler is given by writeHandlerID.

    By default, no handler is registered, the feature must be enabled via NetClientOptions or NetServerOptions.

    Given this ID, a different event loop can send a buffer to that event handler using the event bus and that buffer will be received by this instance in its own event loop and written to the underlying connection. This allows you to write data to other connections which are owned by different event loops.

    Returns string

writeQueueFull

  • writeQueueFull(): boolean
  • This will return true if there are more bytes in the write queue than the value set using {@link NetSocket#setWriteQueueMaxSize}

    Returns boolean

Generated using TypeDoc