SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
WebSocket provides a bidirectional communication channel. Application
developers should use WebSocketFactory#createWebSocket()
function to
create an instance of WebSocket.
Field Summary | |
String
|
binaryType
Type of binary data for message events. |
Number
|
bufferedAmount
(Read only) Number of bytes that are queued to send but not yet written to the network. |
Number(Integer)
|
connectTimeout
(Read only) Connect timeout in milliseconds. |
String
|
extensions
Extensions chosen by the server during the connection handshake. |
Function
|
onclose
CloseEvent handler property. |
Function
|
onerror
ErrorEvent handler property. |
Function
|
onmessage
MessageEvent handler property. |
Function
|
onopen
Event fired when the WebSocket connection opens. |
String
|
protocol
Protocol name selected by the WebSocket server during the connection handshake. |
Number
|
readyState
(Read only) State of the connection. |
String
|
url
(Read only) The location of the WebSocket. |
Constructor Summary | |
WebSocket(url, protocols)
Creates and immedately connects a new WebSocket instance. |
Method Summary | |
void void
|
close(code, reason)
Disconnects the WebSocket. |
ChallengeHandler
|
getChallengeHandler()
Gets the ChallengeHandler that is used during authentication both at the connect-time as well as at subsequent revalidation-time that occurs at regular intervals. |
HttpRedirectPolicy
|
getRedirectPolicy()
Gets the default HTTP redirect policy used in a clustered environment for this connection. |
void
|
send(data)
Sends a WebSocket message containing the given payload. |
void
|
setChallengeHandler(challengeHandler)
Sets the ChallengeHandler that is used during authentication both at the connect-time as well as at subsequent revalidation-time that occurs at regular intervals. |
void
|
setRedirectPolicy(redirectPolicy)
Sets the HTTP redirect policy used in a clustered environment for this connection. |
Event Summary | |
void
|
close()
Event fired when the WebSocket connection closes. |
void
|
error()
Event fired when the WebSocket closes uncleanly. |
void
|
message()
Event fired when a WebSocket message arrives. |
void
|
open()
Event fired when the WebSocket connection opens. |
Field Detail |
String binaryType
SyntaxError
will
be thrown.
NOTE: On older platforms where setter cannot be defined, the value is checked
onmessage is fired.
If set to an invalid value, the error event is fired.
Number bufferedAmount
Number(Integer) connectTimeout
String extensions
Function onclose
Function onerror
Function onmessage
Function onopen
String protocol
Number readyState
String url
Constructor Detail |
WebSocket(url, protocols)
SyntaxError
.
If the port is blocked by the browser or if a secure connection is
attemped from a non-secure origin, the constructor will throw a
SecurityException
.
If any protocol value is invalid or if a protocol appears in the Array
more than once, the constructor will throw a SyntaxError
.
Application developers should use WebSocketFactory.createWebSocket function
to create an instance of WebSocket.
url
- {String}
protocols
- {String|String[]}
Method Detail |
void void close(code, reason)
InvalidAccessError
.
The reason string must be at most 123 bytes when UTF-8 encoded. If the
reason string is too long, close() will throw a SyntaxError
.
code
- {Number} (Optional) A numeric value indicating close code.
reason
- {String} (Optional) A human readable string indicating why the client is closing the WebSocket
void
void
ChallengeHandler getChallengeHandler()
ChallengeHandler
HttpRedirectPolicy getRedirectPolicy()
HttpRedirectPolicy
void send(data)
InvalidStateError
will be thrown.
data
- {String|Blob|ArrayBuffer|ByteBuffer} message payload
void
void setChallengeHandler(challengeHandler)
challengeHandler
- {ChallengeHandler} used for authentication
void
void setRedirectPolicy(redirectPolicy)
redirectPolicy
- {HttpRedirectPolicy} HTTP redirect policy
void
Event Detail |
close()
error()
message()
data
property of the MessageEvent will be a String when
the WebSocket message is a WebSocket text message. It will be the type
specified by binaryType
if the message is a WebSocket
binary message.
open()