Interface WebSocketChannel
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
NettyWebSocketServerChannel
A web socket channel to which can be listened and written to after upgrading a http connection.
- Since:
- 4.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddListener(@NonNull WebSocketListener... listeners) Adds the given listeners to this web socket channel.channel()Get the underlying channel which was upgraded to this web socket channel.Removes all previously registered listeners from this channel.voidSends a close frame into this channel and closes the connection to the recipient without waiting for any kind of response.Get all listeners which were registered to this channel previously.removeListener(@NonNull WebSocketListener... listeners) Removes the given listeners from the channel if they were added previously.removeListener(@NonNull ClassLoader classLoader) Removes all listeners from this channel whose classes were loaded by the given class loader.sendWebSocketFrame(@NonNull WebSocketFrameType webSocketFrameType, byte[] bytes) Sends a web socket frame of the given type into this channel.sendWebSocketFrame(@NonNull WebSocketFrameType webSocketFrameType, @NonNull String text) Sends a web socket frame of the given type into this channel.Methods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
addListener
Adds the given listeners to this web socket channel. Each listener will be called when a web socket frame is received from the wrapped channel.- Parameters:
listeners- the listeners to add.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given listeners are null.
-
removeListener
Removes the given listeners from the channel if they were added previously.- Parameters:
listeners- the listeners to remove.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given listeners are null.
-
removeListener
Removes all listeners from this channel whose classes were loaded by the given class loader.- Parameters:
classLoader- the class loader to remove the listener of.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given class loader is null.
-
clearListeners
Removes all previously registered listeners from this channel.- Returns:
- the same instance as used to call the method, for chaining.
-
listeners
Get all listeners which were registered to this channel previously.- Returns:
- all registered listeners on this channel.
-
sendWebSocketFrame
@NonNull @NonNull WebSocketChannel sendWebSocketFrame(@NonNull @NonNull WebSocketFrameType webSocketFrameType, @NonNull @NonNull String text) Sends a web socket frame of the given type into this channel. This method sends frames of the type PING, PONG and TEXT. Any other type will be silently converted to a binary frame holding the given text in its body. This method call is equivalent tochannel.sendWebSocketFrame(type, text.getBytes(StandardCharsets.UTF_8)).- Parameters:
webSocketFrameType- the type of web socket frame to send.text- the string content of the frame.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if either the given type or text is null.
-
sendWebSocketFrame
@NonNull @NonNull WebSocketChannel sendWebSocketFrame(@NonNull @NonNull WebSocketFrameType webSocketFrameType, byte[] bytes) Sends a web socket frame of the given type into this channel. This method sends frames of the type PING, PONG and TEXT. Any other type will be silently converted to a binary frame holding the given bytes in its body. To send a close frame useclose(int, String)instead.- Parameters:
webSocketFrameType- the type of web socket frame to send.bytes- the bytes to put into the frame body.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given type is null.
-
close
Sends a close frame into this channel and closes the connection to the recipient without waiting for any kind of response. Any listener added to this channel can change the given reason status code and the reason text. The given status code must be valid as defined in RFC 6455.- Parameters:
statusCode- the status code of the close, must be valid as per RFC-6455.reasonText- the reason text for the close, no text indicates no special reason.- Throws:
IllegalArgumentException- if an invalid status code was provided.
-
channel
Get the underlying channel which was upgraded to this web socket channel.- Returns:
- the original, now upgraded channel.
-