connect(), then receive events like onMessage(String) via the overloaded
methods and to send(String) data to the server.
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private CountDownLatch | closeLatch
The latch for closeBlocking() |
| private CountDownLatch | connectLatch
The latch for connectBlocking() |
| private Thread | connectReadThread
The thread to connect and read message |
| private int | connectTimeout
The socket timeout value to be used in milliseconds. |
| private DnsResolver | dnsResolver
DNS resolver that translates a URI to an InetAddress |
| private Draft | draft
The draft to use |
| private WebSocketImpl | engine
The underlying engine |
| private Map | headers
The additional headers to use |
| private OutputStream | ostream
The used OutputStream |
| private Proxy | proxy
The used proxy, if any |
| private Socket | socket
The socket for this WebSocketClient |
| private SocketFactory | socketFactory
The SocketFactory for this WebSocketClient |
| protected URI | uri
The URI this channel is supposed to connect to. |
| private Thread | writeThread
The thread to write outgoing message |
| Access | Constructor and Description |
|---|---|
| public | WebSocketClient(URI
the server URI to connect to serverUri)Constructs a WebSocketClient instance and sets it to the connect to the specified URI. |
| public | WebSocketClient(URI
the server URI to connect to serverUri, Draft The draft which should be used for this connection protocolDraft)Constructs a WebSocketClient instance and sets it to the connect to the specified URI. |
| public | WebSocketClient(URI
the server URI to connect to serverUri, Map<String, String> Additional HTTP-Headers httpHeaders)Constructs a WebSocketClient instance and sets it to the connect to the specified URI. |
| public | |
| public | WebSocketClient(URI
the server URI to connect to serverUri, Draft The draft which should be used for this connection protocolDraft, Map<String, String> Additional HTTP-Headers httpHeaders, int The Timeout for the connection connectTimeout)Constructs a WebSocketClient instance and sets it to the connect to the specified URI. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public void | |
| public void | |
| public void | close(int code, String message)
Implements org. sends the closing handshake. |
| public void | |
| public void | closeConnection(int code, String message)
Implements org. This will close the connection immediately without a proper close handshake. |
| public void | |
| public boolean | Returns: Returns whether it succeeded or not.Same as |
| public boolean | Returns: Returns whether it succeeded or not.The connect timeout timeout, TimeUnit The timeout time unit timeUnit)Same as |
| public <T> T | getAttachment()
Implements org. Getter for the connection attachment. |
| public WebSocket | |
| protected Collection | getConnections()
Implements abstract org. Getter to get all the currently available connections |
| public Draft | Returns: The draft used for this clientImplements org. Returns the protocol version this channel uses. |
| public InetSocketAddress | |
| public InetSocketAddress | getLocalSocketAddress()
Implements org. Returns the address of the endpoint this socket is bound to, or |
| private int | Returns: the specified port or the default port for the specific schemeExtract the specified port |
| public IProtocol | getProtocol()
Implements org. Returns the used Sec-WebSocket-Protocol for this websocket connection |
| public ReadyState | getReadyState()
Implements org. This represents the state of the connection. |
| public InetSocketAddress | |
| public InetSocketAddress | getRemoteSocketAddress()
Implements org. Returns the address of the endpoint this socket is connected to, or |
| public String | getResourceDescriptor()
Implements org. Returns the HTTP Request-URI as defined by http://tools.ietf.org/html/rfc2616#section-5.1.2 If the opening handshake has not yet happened it will return null. |
| public Socket | Returns: the socket used for this connectionReturns the socket to allow Hostname Verification |
| public SSLSession | getSSLSession()
Implements org. Returns the ssl session of websocket, if ssl/wss is used for this instance. |
| public URI | |
| private void | handleIOException(IOException
the IOException causing a eot. e)Method to give some additional info for specific IOExceptions |
| public boolean | hasBufferedData()
Implements org. Checks if the websocket has buffered data |
| public boolean | hasSSLSupport()
Implements org. Does this websocket use an encrypted (wss/ssl) or unencrypted (ws) connection |
| public boolean | |
| public boolean | |
| public boolean | isFlushAndClose()
Implements org. Returns true when no further frames may be submitted This happens before the socket connection is closed. |
| public boolean | |
| public abstract void | onClose(int
The codes can be looked up here: code, String CloseFrameAdditional information string reason, boolean Returns whether or not the closing of the connection was initiated by the remote
host. remote)Called after the websocket connection has been closed. |
| public void | onCloseInitiated(int
The codes can be looked up here: code, String CloseFrameAdditional information string reason)Send when this peer sends a close handshake |
| public void | onClosing(int
The codes can be looked up here: code, String CloseFrameAdditional information string reason, boolean Returns whether or not the closing of the connection was initiated by the remote
host. remote)Called as soon as no further frames are accepted |
| public abstract void | |
| public abstract void | |
| public void | onMessage(ByteBuffer
The binary message that was received. bytes)Callback for binary messages received from the remote host |
| public abstract void | onOpen(ServerHandshake
The handshake of the websocket instance handshakedata)Called after an opening handshake has been performed and the given websocket is ready to be written on. |
| protected void | onSetSSLParameters(SSLParameters
the SSLParameters which will be used for the SSLSocket sslParameters)Apply specific SSLParameters If you override this method make sure to always call super.onSetSSLParameters() to ensure the hostname validation is active |
| public final void | onWebsocketClose(WebSocket conn, int code, String reason, boolean remote)
Implements org. Calls subclass' implementation of onClose. |
| public void | onWebsocketCloseInitiated(WebSocket conn, int code, String reason)
Implements org. send when this peer sends a close handshake |
| public void | onWebsocketClosing(WebSocket conn, int code, String reason, boolean remote)
Implements org. Called as soon as no further frames are accepted |
| public final void | onWebsocketError(WebSocket conn, Exception ex)
Implements org. Calls subclass' implementation of onIOError. |
| public final void | onWebsocketMessage(WebSocket conn, String message)
Implements org. Calls subclass' implementation of onMessage. |
| public final void | onWebsocketMessage(WebSocket conn, ByteBuffer blob)
Implements org. Called when an entire binary frame has been received. |
| public final void | onWebsocketOpen(WebSocket conn, Handshakedata handshake)
Implements org. Calls subclass' implementation of onOpen. |
| public final void | onWriteDemand(WebSocket conn)
Implements org. This method is used to inform the selector thread that there is data queued to be written to the socket. |
| private boolean | |
| public void | |
| public boolean | Returns: Returns whether it succeeded or not.Same as |
| public String | Returns: the previous value associated with key, or null if there was no mapping for key.Name of the header to remove. key)
|
| private void | |
| public void | |
| public void | send(String
The string which will be transmitted. text)Implements org. Sends text to the connected websocket server. |
| public void | send(byte[]
The byte-Array of data to send to the WebSocket server. data)Implements org. Sends binary data to the connected webSocket server. |
| public void | send(ByteBuffer bytes)
Implements org. Send Binary data (plain bytes) to the other end. |
| public void | sendFragmentedFrame(Opcode op, ByteBuffer buffer, boolean fin)
Implements org. Allows to send continuous/fragmented frames conveniently. |
| public void | sendFrame(Framedata framedata)
Implements org. Send a frame to the other end |
| public void | sendFrame(Collection<Framedata> frames)
Implements org. Send a collection of frames to the other end |
| private void | |
| public void | |
| public <T> void | setAttachment(T attachment)
Implements org. Setter for an attachment on the socket connection. |
| public void | |
| public void | |
| public void | |
| public void | setSocketFactory(SocketFactory
The socket factory which should be used for the connection. socketFactory)Accepts a SocketFactory. |
| private void |