Groovy Documentation

## org.vertx.groovy.core.net
[Groovy] Class NetSocket

    java.lang.Object
      org.vertx.groovy.core.net.NetSocket

All Implemented Interfaces:
  ReadStream, WriteStream

    class NetSocket

Represents a socket-like interface to a TCP/SSL 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 ReadStream and WriteStream so it can be used with Pump to pump data with flow control.

Instances of this class are not thread-safe.

Authors:
  Peter Ledbrook
  Tim Fox

Constructor Summary
`protected NetSocket(JNetSocket jSocket)`

Method Summary
`void` | `close()` Close the socket
`void` | `closedHandler(groovy.lang.Closure handler)` {@inheritDoc}
`void` | `dataHandler(groovy.lang.Closure dataHandler)` {@inheritDoc}
`void` | `drainHandler(groovy.lang.Closure drainHandler)` {@inheritDoc}
`void` | `endHandler(groovy.lang.Closure endHandler)` {@inheritDoc}
`void` | `exceptionHandler(groovy.lang.Closure handler)` {@inheritDoc}
`java.lang.String` | `getWriteHandlerID()` @return 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` | `isWriteQueueFull()` {@inheritDoc}
`NetSocket` | `leftShift(Buffer buff)` Same as write(Buffer)
`NetSocket` | `leftShift(java.lang.String str)` Same as write(String)
`void` | `pause()` {@inheritDoc}
`void` | `resume()` {@inheritDoc}
`void` | `sendFile(java.lang.String filename)` Tell the kernel 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.
`void` | `setWriteQueueMaxSize(int size)` {@inheritDoc}
`NetSocket` | `write(Buffer data)` Write a Buffer to the request body.
`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`.
`NetSocket` | `write(Buffer data, groovy.lang.Closure doneHandler)` Write a Buffer to the connection.
`NetSocket` | `write(java.lang.String str, groovy.lang.Closure doneHandler)` Write a java.lang.String to the connection, encoded in UTF-8.
`NetSocket` | `write(java.lang.String str, java.lang.String enc, groovy.lang.Closure doneHandler)` Write a java.lang.String to the connection, encoded with encoding `enc`.
`void` | `writeBuffer(Buffer data)` {@inheritDoc}

Methods inherited from 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

    protected NetSocket(JNetSocket jSocket)

Method Detail

### close

    void close()

  Close the socket

### closedHandler

    void closedHandler(groovy.lang.Closure handler)

  {@inheritDoc}

### dataHandler

    void dataHandler(groovy.lang.Closure dataHandler)

  {@inheritDoc}

### drainHandler

    void drainHandler(groovy.lang.Closure drainHandler)

  {@inheritDoc}

### endHandler

    void endHandler(groovy.lang.Closure endHandler)

  {@inheritDoc}

### exceptionHandler

    void exceptionHandler(groovy.lang.Closure handler)

  {@inheritDoc}

### getWriteHandlerID

    java.lang.String getWriteHandlerID()

  Returns:
    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.

### isWriteQueueFull

    boolean isWriteQueueFull()

  {@inheritDoc}

### leftShift

    NetSocket leftShift(Buffer buff)

  Same as write(Buffer)

### leftShift

    NetSocket leftShift(java.lang.String str)

  Same as write(String)

### pause

    void pause()

  {@inheritDoc}

### resume

    void resume()

  {@inheritDoc}

### sendFile

    void sendFile(java.lang.String filename)

  Tell the kernel 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.

### setWriteQueueMaxSize

    void setWriteQueueMaxSize(int size)

  {@inheritDoc}

### write

    NetSocket write(Buffer data)

  Write a Buffer to the request body.

  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    NetSocket write(java.lang.String str)

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

  Returns:
    A reference to this, so multiple method calls can be chained.

### 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 multiple method calls can be chained.

### write

    NetSocket write(Buffer data, groovy.lang.Closure doneHandler)

  Write a Buffer to the connection. The `doneHandler` is called after the buffer is actually written to the wire.

  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    NetSocket write(java.lang.String str, groovy.lang.Closure doneHandler)

  Write a java.lang.String to the connection, encoded in UTF-8. The `doneHandler` is called after the buffer is actually written to the wire.

  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    NetSocket write(java.lang.String str, java.lang.String enc, groovy.lang.Closure doneHandler)

  Write a java.lang.String to the connection, encoded with encoding `enc`. The `doneHandler` is called after the buffer is actually written to the wire.

  Returns:
    A reference to this, so multiple method calls can be chained.

### writeBuffer

    void writeBuffer(Buffer data)

  {@inheritDoc}

Groovy Documentation