类 WebSocketClient
java.lang.Object
net.apexes.wsonrpc.client.support.websocket.WebSocketClient
-
嵌套类概要
嵌套类 -
构造器概要
构造器构造器说明WebSocketClient(URI url) Create a websocket to connect to a given serverWebSocketClient(URI url, String protocol) Create a websocket to connect to a given server.Create a websocket to connect to a given server. -
方法概要
修饰符和类型方法说明voidBlocks until both threads exit.voidclose()Close down the socket.voidconnect(int connectTimeout, int soTimeout) Start up the socket.getState()protected voidonPong(byte[] payload) voidping(byte[] bytes) voidsend(byte[] data) Send a BINARY message over the socketvoidSend a TEXT message over the socketvoidsetEventHandler(WebSocketEventHandler eventHandler) Must be called before connect().voidsetHostnameVerifier(HostnameVerifier hostNameVerifier) voidsetSocketFactory(SocketFactory socketFactory) static voidsetThreadFactory(ThreadFactory threadFactory, ThreadInitializer intializer)
-
构造器详细资料
-
WebSocketClient
Create a websocket to connect to a given server- 参数:
url- The URL of a websocket server
-
WebSocketClient
Create a websocket to connect to a given server. Include protocol in websocket handshake- 参数:
url- The URL of a websocket serverprotocol- The protocol to include in the handshake. If null, it will be omitted
-
WebSocketClient
Create a websocket to connect to a given server. Include the given protocol in the handshake, as well as any extra HTTP headers specified. Useful if you would like to include a User-Agent or other header- 参数:
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 requested
-
-
方法详细资料
-
setThreadFactory
-
setSocketFactory
-
setHostnameVerifier
-
setEventHandler
Must be called before connect(). Set the support for all websocket-related events.- 参数:
eventHandler- The support to be triggered with relevant events
-
getEventHandler
-
getState
-
connect
public void connect(int connectTimeout, int soTimeout) Start up the socket. This is non-blocking, it will fire up the threads used by the library and then trigger the onOpen support once the connection is established. -
send
Send a TEXT message over the socket- 参数:
data- The text payload to be sent
-
send
public void send(byte[] data) Send a BINARY message over the socket- 参数:
data- The binary payload to be sent
-
ping
public void ping(byte[] bytes) -
onPong
protected void onPong(byte[] payload) -
close
public void close()Close down the socket. Will trigger the onClose support if the socket has not been previously closed. -
blockClose
Blocks until both threads exit. The actual close must be triggered separately. This is just a convenience method to make sure everything shuts down, if desired.
-