public class WebSocketClient extends Object
| 构造器和说明 |
|---|
WebSocketClient(URI url)
Create a websocket to connect to a given server
|
WebSocketClient(URI url,
String protocol)
Create a websocket to connect to a given server.
|
WebSocketClient(URI url,
String protocol,
Map<String,String> extraHeaders)
Create a websocket to connect to a given server.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
blockClose()
Blocks until both threads exit.
|
void |
close()
Close down the socket.
|
void |
connect()
Start up the socket.
|
void |
ping() |
void |
send(byte[] data)
Send a BINARY message over the socket
|
void |
send(String data)
Send a TEXT message over the socket
|
void |
setEventHandler(WebSocketEventHandler eventHandler)
Must be called before connect().
|
static void |
setHostnameVerifier(HostnameVerifier hostNameVerifier) |
static void |
setThreadFactory(ThreadFactory threadFactory,
ThreadInitializer intializer) |
public WebSocketClient(URI url)
url - The URL of a websocket serverpublic WebSocketClient(URI url, String protocol)
url - The URL of a websocket serverprotocol - The protocol to include in the handshake. If null, it will be omittedpublic WebSocketClient(URI url, String protocol, Map<String,String> extraHeaders)
url - The URL of a websocket serverprotocol - The protocol to include in the handshake. If null, it will be omittedextraHeaders - Any extra HTTP headers to be included with the initial request. Pass null if not extra headers
are requestedpublic static void setThreadFactory(ThreadFactory threadFactory, ThreadInitializer intializer)
public static void setHostnameVerifier(HostnameVerifier hostNameVerifier)
public void setEventHandler(WebSocketEventHandler eventHandler)
eventHandler - The handler to be triggered with relevant eventspublic void connect()
public void send(String data)
data - The text payload to be sentpublic void send(byte[] data)
data - The binary payload to be sentpublic void ping()
public void close()
public void blockClose()
throws InterruptedException
Copyright © 2017. All rights reserved.