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 Pump to pump data with flow control.

no subtypes hierarchy

Initializer
NetSocket(NetSocket unknown)
Inherited Attributes
Attributes inherited from: Object
hash, string
Methods
closeshared default void close()

Close the NetSocket

closeHandlershared default NetSocket closeHandler(Anything()? handler)

Set a handler that will be called when the NetSocket is closed

Parameters:
  • handler

    the handler

drainHandlershared actual default NetSocket drainHandler(Anything()? handler)

Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See Pump for an example of this being used.

The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to maxSize / 2.

endshared actual default void end()

Calls close

endshared actual default void end(Buffer t)

Same as end but writes some data to the stream before ending.

endHandlershared actual default NetSocket endHandler(Anything()? endHandler)

Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.

exceptionHandlershared actual default NetSocket exceptionHandler(Anything(Throwable)? handler)

Set an exception handler.

handlershared actual default NetSocket handler(Anything(Buffer)? handler)

Set a data handler. As data is read, the handler will be called with the data.

indicatedServerNameshared default String indicatedServerName()

Returns the SNI server name presented during the SSL handshake by the client.

isSslshared default Boolean isSsl()
localAddressshared default SocketAddress localAddress()
pauseshared actual default NetSocket pause()

Pause the ReadSupport. While it's paused, no data will be sent to the dataHandler

remoteAddressshared default SocketAddress remoteAddress()
resumeshared actual default NetSocket resume()

Resume reading. If the ReadSupport has been paused, reading will recommence on it.

sendFileshared default NetSocket sendFile(String filename)

Tell the operating system to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to stream files.

Parameters:
  • filename

    file name of the file to send

sendFileshared default NetSocket sendFile(String filename, Anything(Throwable?) resultHandler)

Same as sendFile but also takes a handler that will be called when the send has completed or a failure has occurred

Parameters:
  • filename

    file name of the file to send

  • resultHandler

    handler

sendFileshared default NetSocket sendFile(String filename, Integer offset)

Tell the operating system to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to stream files.

Parameters:
  • filename

    file name of the file to send

  • offset

    offset

sendFileshared default NetSocket sendFile(String filename, Integer offset, Anything(Throwable?) resultHandler)

Same as sendFile but also takes a handler that will be called when the send has completed or a failure has occurred

Parameters:
  • filename

    file name of the file to send

  • offset

    offset

  • resultHandler

    handler

sendFileshared default NetSocket sendFile(String filename, Integer offset, Integer length)

Tell the operating system to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to stream files.

Parameters:
  • filename

    file name of the file to send

  • offset

    offset

  • length

    length

sendFileshared default NetSocket sendFile(String filename, Integer offset, Integer length, Anything(Throwable?) resultHandler)

Same as sendFile but also takes a handler that will be called when the send has completed or a failure has occurred

Parameters:
  • filename

    file name of the file to send

  • offset

    offset

  • length

    length

  • resultHandler

    handler

setWriteQueueMaxSizeshared actual default NetSocket setWriteQueueMaxSize(Integer maxSize)

Set the maximum size of the write queue to maxSize. You will still be able to write to the stream even if there is more than maxSize items in the write queue. This is used as an indicator by classes such as Pump to provide flow control.

The value is defined by the implementation of the stream, e.g in bytes for a NetSocket, the number of Message for a MessageProducer, etc…

upgradeToSslshared default NetSocket upgradeToSsl(Anything() handler)

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

Parameters:
  • handler

    the handler will be notified when it's upgraded

upgradeToSslshared default NetSocket upgradeToSsl(String serverName, Anything() handler)

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

Parameters:
  • serverName

    the server name

  • handler

    the handler will be notified when it's upgraded

writeshared actual default NetSocket write(Buffer data)
writeshared default NetSocket write(String str)

Write a String to the connection, encoded in UTF-8.

Parameters:
  • str

    the string to write

writeshared default NetSocket write(String str, String enc)

Write a String to the connection, encoded using the encoding enc.

Parameters:
  • str

    the string to write

  • enc

    the encoding to use

writeHandlerIDshared default String writeHandlerID()

When a NetSocket is created it automatically registers an event handler with the event bus, the ID of that handler is given by writeHandlerID.

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.

writeQueueFullshared actual default Boolean writeQueueFull()

This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize

Inherited Methods
Methods inherited from: Object
equals
Methods inherited from: ReadStream<T>
Methods inherited from: StreamBase
Methods inherited from: WriteStream<T>