WebSocket
Date: 2010-07-28

Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## net.tootallnate.websocket
Class WebSocket

    java.lang.Object
      net.tootallnate.websocket.WebSocket

    public final class WebSocket

extends java.lang.Object

Represents one end (client or server) of a single WebSocket connection. Takes care of the "handshake" phase, then allows for easy sending of text frames, and recieving frames through an event-based model. This is an inner class, used by `WebSocketClient` and `WebSocketServer`, and should never need to be instantiated directly by your code. However, instances are exposed in `WebSocketServer` through the onClientOpen, onClientClose, onClientMessage callbacks.

Author:
  Nathan Rajlich

Field Summary
`static byte` | `CR` The byte representing CR, or Carriage Return, or \r
`static int` | `DEFAULT_PORT` The default port of WebSockets, as defined in the spec.
`static byte` | `END_OF_FRAME` The byte representing the end of a WebSocket text frame.
`static byte` | `LF` The byte representing LF, or Line Feed, or \n
`static byte` | `START_OF_FRAME` The byte representing the beginning of a WebSocket text frame.
`static java.nio.charset.Charset` | `UTF8_CHARSET` The WebSocket protocol expects UTF-8 encoded bytes.

Method Summary
`void` | `close()` Closes the underlying SocketChannel, and calls the listener's onClose event handler.
`void` | `send(java.lang.String text)`
`java.nio.channels.SocketChannel` | `socketChannel()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_PORT

    public static final int DEFAULT_PORT

  The default port of WebSockets, as defined in the spec. If the nullary constructor is used, DEFAULT_PORT will be the port the WebSocketServer is binded to. Note that ports under 1024 usually require root permissions.

  See Also:
    Constant Field Values

### UTF8_CHARSET

    public static final java.nio.charset.Charset UTF8_CHARSET

  The WebSocket protocol expects UTF-8 encoded bytes.

### CR

    public static final byte CR

  The byte representing CR, or Carriage Return, or \r

  See Also:
    Constant Field Values

### LF

    public static final byte LF

  The byte representing LF, or Line Feed, or \n

  See Also:
    Constant Field Values

### START_OF_FRAME

    public static final byte START_OF_FRAME

  The byte representing the beginning of a WebSocket text frame.

  See Also:
    Constant Field Values

### END_OF_FRAME

    public static final byte END_OF_FRAME

  The byte representing the end of a WebSocket text frame.

  See Also:
    Constant Field Values

Method Detail

### close

    public void close()
               throws java.io.IOException

  Closes the underlying SocketChannel, and calls the listener's onClose event handler.

  Throws:
    `java.io.IOException` - When socket related I/O errors occur.

### send

    public void send(java.lang.String text)
              throws java.io.IOException

  Throws:
    `java.io.IOException`

### socketChannel

    public java.nio.channels.SocketChannel socketChannel()

Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD