Package: io.vertx.groovy.core.net

## [Groovy] Class NetSocket

- io.vertx.groovy.core.net.NetSocket

- All Implemented Interfaces and Traits:
    ReadStream, WriteStream

      @groovy.transform.CompileStatic
      class NetSocket
      extends java.lang.Object

  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.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `NetSocket (java.lang.Object delegate)`

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `void` | `close()` Close the NetSocket
    `NetSocket` | `closeHandler(io.vertx.core.Handler<java.lang.Void> handler)` Set a handler that will be called when the NetSocket is closed
    `NetSocket` | `drainHandler(io.vertx.core.Handler<java.lang.Void> handler)`
    `void` | `end(Buffer t)` Same as NetSocket.end but writes some data to the stream before ending.
    `void` | `end()` Calls NetSocket.close
    `NetSocket` | `endHandler(io.vertx.core.Handler<java.lang.Void> endHandler)`
    `NetSocket` | `exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler)`
    `java.lang.Object` | `getDelegate()`
    `NetSocket` | `handler(io.vertx.core.Handler<Buffer> handler)`
    `boolean` | `isSsl()` Returns: true if this NetSocket is encrypted via SSL/TLS.
    `SocketAddress` | `localAddress()` @return Returns: the local address for this socket
    `NetSocket` | `pause()`
    `SocketAddress` | `remoteAddress()` @return Returns: the remote address for this socket
    `NetSocket` | `resume()`
    `NetSocket` | `sendFile(java.lang.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.
    `NetSocket` | `sendFile(java.lang.String filename, long 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.
    `NetSocket` | `sendFile(java.lang.String filename, long offset, long 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.
    `NetSocket` | `sendFile(java.lang.String filename, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)` Same as NetSocket.sendFile but also takes a handler that will be called when the send has completed or a failure has occurred
    `NetSocket` | `sendFile(java.lang.String filename, long offset, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)` Same as NetSocket.sendFile but also takes a handler that will be called when the send has completed or a failure has occurred
    `NetSocket` | `sendFile(java.lang.String filename, long offset, long length, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)` Same as NetSocket.sendFile but also takes a handler that will be called when the send has completed or a failure has occurred
    `NetSocket` | `setWriteQueueMaxSize(int maxSize)`
    `NetSocket` | `upgradeToSsl(io.vertx.core.Handler<java.lang.Void> handler)` Upgrade channel to use SSL/TLS.
    `NetSocket` | `write(Buffer data)`
    `NetSocket` | `write(java.lang.String str)` Write a java.lang.String to the connection, encoded in UTF-8.
    `NetSocket` | `write(java.lang.String str, java.lang.String enc)` Write a java.lang.String to the connection, encoded using the encoding `enc`.
    `java.lang.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`.
    `boolean` | `writeQueueFull()` This will return `true` if there are more bytes in the write queue than the value set using NetSocket.setWriteQueueMaxSize

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Constructor Detail

    - #### NetSocket(java.lang.Object delegate)

  - ### Method Detail

    - #### void close()

      Close the NetSocket

    - #### NetSocket closeHandler(io.vertx.core.Handler<java.lang.Void> handler)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `handler` - the handler

    - #### NetSocket drainHandler(io.vertx.core.Handler<java.lang.Void> handler)

    - #### void end(Buffer t)

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

      Parameters:
        t

    - #### void end()

      Calls NetSocket.close

    - #### NetSocket endHandler(io.vertx.core.Handler<java.lang.Void> endHandler)

    - #### NetSocket exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler)

    - #### java.lang.Object getDelegate()

    - #### NetSocket handler(io.vertx.core.Handler<Buffer> handler)

    - #### boolean isSsl()

      Returns:
        true if this NetSocket is encrypted via SSL/TLS.

    - #### SocketAddress localAddress()

      Returns:
        the local address for this socket

    - #### NetSocket pause()

    - #### SocketAddress remoteAddress()

      Returns:
        the remote address for this socket

    - #### NetSocket resume()

    - #### NetSocket sendFile(java.lang.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.

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `filename` - file name of the file to send

    - #### NetSocket sendFile(java.lang.String filename, long 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.

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `filename` - file name of the file to send
        `offset` - offset

    - #### NetSocket sendFile(java.lang.String filename, long offset, long 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.

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `filename` - file name of the file to send
        `offset` - offset
        `length` - length

    - #### NetSocket sendFile(java.lang.String filename, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `filename` - file name of the file to send
        `resultHandler` - handler

    - #### NetSocket sendFile(java.lang.String filename, long offset, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `filename` - file name of the file to send
        `offset` - offset
        `resultHandler` - handler

    - #### NetSocket sendFile(java.lang.String filename, long offset, long length, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `filename` - file name of the file to send
        `offset` - offset
        `length` - length
        `resultHandler` - handler

    - #### NetSocket setWriteQueueMaxSize(int maxSize)

    - #### NetSocket upgradeToSsl(io.vertx.core.Handler<java.lang.Void> handler)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `handler` - the handler will be notified when it's upgraded

    - #### NetSocket write(Buffer data)

    - #### NetSocket write(java.lang.String str)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `str` - the string to write

    - #### NetSocket write(java.lang.String str, java.lang.String enc)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `str` - the string to write
        `enc` - the encoding to use

    - #### java.lang.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.

      Returns:
        the write handler ID

    - #### boolean writeQueueFull()

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

      Returns:
        true if write queue is full