public class WebSocket extends Object
Modifier and Type | Class and Description |
---|---|
static class |
WebSocket.CloseEvent |
static interface |
WebSocket.CloseHandler |
static class |
WebSocket.ErrorEvent |
static interface |
WebSocket.ErrorHandler |
static class |
WebSocket.MessageEvent |
static interface |
WebSocket.MessageHandler |
static class |
WebSocket.OpenEvent |
static interface |
WebSocket.OpenHandler |
static class |
WebSocket.ReadyState |
Modifier | Constructor and Description |
---|---|
|
WebSocket(String URL) |
|
WebSocket(String URL,
String[] protocols)
Creates a new WebSocket instance and connects to the remote socket location.
|
protected |
WebSocket(WebSocketFactory factory,
String URL,
String[] protocols) |
Modifier and Type | Method and Description |
---|---|
void |
addCloseHandler(WebSocket.CloseHandler handler)
The onclose handler is called when the connection is terminated.
|
void |
addErrorHandler(WebSocket.ErrorHandler handler)
The onclose handler is called when an error occurs.
|
void |
addMessageHandler(WebSocket.MessageHandler handler)
The onmessage handler is called when data arrives.
|
void |
addOpenHandler(WebSocket.OpenHandler handler)
The onopen handler is called when the connection is established.
|
String |
binaryType()
message event data type for binary messages
valid values are: "bytebuffer", "blob" and "arraybuffer"
|
void |
binaryType(String newBinaryType) |
void |
close()
Disconnects the remote socket location.
|
void |
close(int code,
String reason)
Disconnects the remote socket location with code and reason.
|
int |
getBufferedAmount()
The number of bytes queued to be sent
|
int |
getReadyState()
The ready state indicates the connection status.
|
String |
getURL()
The URL with which the WebSocket was constructed.
|
protected void |
handleClose(NativeCloseEvent event) |
protected void |
handleError() |
protected void |
handleMessage(NativeMessageEvent event) |
protected void |
handleOpen() |
void |
send(ByteBuffer data)
Sends binary-based data to the remote socket location.
|
void |
send(String data)
Sends text-based data to the remote socket location.
|
public WebSocket(String URL, String[] protocols) throws WebSocketException
{String}
- location The socket location{String}
- [protocol] The subprotocol to be communicated over the WebSocketWebSocketException
public WebSocket(String URL) throws WebSocketException
WebSocketException
protected WebSocket(WebSocketFactory factory, String URL, String[] protocols) throws WebSocketException
WebSocketException
public String getURL()
public int getReadyState()
public int getBufferedAmount()
public String binaryType()
public void binaryType(String newBinaryType)
public void close()
public void close(int code, String reason)
{int}
- code close code{String}
- reason the close reasonpublic void send(String data)
{JavaScriptObject}
- data the data payloadpublic void send(ByteBuffer data)
{ByteBuffer}
- data the data payloadpublic void addOpenHandler(WebSocket.OpenHandler handler)
protected void handleOpen()
public void addMessageHandler(WebSocket.MessageHandler handler)
protected void handleMessage(NativeMessageEvent event)
public void addCloseHandler(WebSocket.CloseHandler handler)
protected void handleClose(NativeCloseEvent event)
public void addErrorHandler(WebSocket.ErrorHandler handler)
protected void handleError()
Copyright © 2015. All Rights Reserved.