org.vertx.java.core.http

## Class WebSocket

- java.lang.Object
- - org.vertx.java.core.http.WebSocket

All Implemented Interfaces:
  ReadStream, WriteStream

Direct Known Subclasses:
  ServerWebSocket

    public abstract class WebSocket
    extends java.lang.Object
    implements ReadStream, WriteStream

Represents an HTML 5 Websocket

Instances of this class are created and provided to the handler of an `HttpClient` when a successful websocket connect attempt occurs.

On the server side, the subclass `ServerWebSocket` is used instead.

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

### Field Summary

Fields
`java.lang.String` `binaryHandlerID` When a `Websocket` is created it automatically registers an event handler with the eventbus, the ID of that handler is given by `binaryHandlerID`.
`java.lang.String` `textHandlerID` When a `Websocket` is created it automatically registers an event handler with the eventbus, the ID of that handler is given by `textHandlerID`.

### Constructor Summary

Constructors
`protected` `WebSocket(java.lang.String binaryHandlerID, java.lang.String textHandlerID)`

### Method Summary

Methods
`abstract void` `close()` Close the websocket
`abstract void` `closedHandler(Handler<java.lang.Void> handler)` Set a closed handler on the connection
`abstract void` `writeBinaryFrame(Buffer data)` Write `data` to the websocket as a binary frame
`abstract void` `writeTextFrame(java.lang.String str)` Write `str` to the websocket as a text frame

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.vertx.java.core.streams.ReadStream

`dataHandler, endHandler, exceptionHandler, pause, resume`

### Methods inherited from interface org.vertx.java.core.streams.WriteStream

`drainHandler, exceptionHandler, setWriteQueueMaxSize, writeBuffer, writeQueueFull`

### Field Detail

#### binaryHandlerID

    public final java.lang.String binaryHandlerID

When a `Websocket` is created it automatically registers an event handler with the eventbus, the ID of that handler is given by `binaryHandlerID`.

Given this ID, a different event loop can send a binary frame 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 websockets which are owned by different event loops.

#### textHandlerID

    public final java.lang.String textHandlerID

When a `Websocket` is created it automatically registers an event handler with the eventbus, the ID of that handler is given by `textHandlerID`.

Given this ID, a different event loop can send a text frame 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 websockets which are owned by different event loops.

### Constructor Detail

#### WebSocket

    protected WebSocket(java.lang.String binaryHandlerID,
             java.lang.String textHandlerID)

### Method Detail

#### writeBinaryFrame

    public abstract void writeBinaryFrame(Buffer data)

Write `data` to the websocket as a binary frame

#### writeTextFrame

    public abstract void writeTextFrame(java.lang.String str)

Write `str` to the websocket as a text frame

#### closedHandler

    public abstract void closedHandler(Handler<java.lang.Void> handler)

Set a closed handler on the connection

#### close

    public abstract void close()

Close the websocket