Package org.asynchttpclient.netty.ws
Class NettyWebSocket
- java.lang.Object
-
- org.asynchttpclient.netty.ws.NettyWebSocket
-
-
Constructor Summary
Constructors Constructor Description NettyWebSocket(io.netty.channel.Channel channel, io.netty.handler.codec.http.HttpHeaders upgradeHeaders)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WebSocketaddWebSocketListener(WebSocketListener l)Add aWebSocketListenervoidbufferFrame(io.netty.handler.codec.http.websocketx.WebSocketFrame frame)SocketAddressgetLocalAddress()Get local address client initiated request from.SocketAddressgetRemoteAddress()Get remote address client initiated request to.io.netty.handler.codec.http.HttpHeadersgetUpgradeHeaders()voidhandleFrame(io.netty.handler.codec.http.websocketx.WebSocketFrame frame)booleanisOpen()booleanisReady()voidonClose(int code, String reason)voidonError(Throwable t)voidprocessBufferedFrames()WebSocketremoveWebSocketListener(WebSocketListener l)Remove aWebSocketListenerio.netty.util.concurrent.Future<Void>sendBinaryFrame(byte[] payload)Send a full binary frame.io.netty.util.concurrent.Future<Void>sendBinaryFrame(byte[] payload, boolean finalFragment, int rsv)Allows sending a binary frame with fragmentation or extension bits.io.netty.util.concurrent.Future<Void>sendBinaryFrame(io.netty.buffer.ByteBuf payload, boolean finalFragment, int rsv)Allows sending a binary frame with fragmentation or extension bits.io.netty.util.concurrent.Future<Void>sendCloseFrame()Send an empty close frame.io.netty.util.concurrent.Future<Void>sendCloseFrame(int statusCode, String reasonText)Send an empty close frame.io.netty.util.concurrent.Future<Void>sendContinuationFrame(byte[] payload, boolean finalFragment, int rsv)Send a binary continuation frame.io.netty.util.concurrent.Future<Void>sendContinuationFrame(io.netty.buffer.ByteBuf payload, boolean finalFragment, int rsv)Send a continuation frame (those are actually untyped as counterpart must have memorized first fragmented frame type).io.netty.util.concurrent.Future<Void>sendContinuationFrame(String payload, boolean finalFragment, int rsv)Send a text continuation frame.io.netty.util.concurrent.Future<Void>sendPingFrame()Send an empty ping frameio.netty.util.concurrent.Future<Void>sendPingFrame(byte[] payload)Send a ping frame with a byte array payload (limited to 125 bytes or fewer).io.netty.util.concurrent.Future<Void>sendPingFrame(io.netty.buffer.ByteBuf payload)Send a ping frame with a ByteBuf payload (limited to 125 bytes or fewer).io.netty.util.concurrent.Future<Void>sendPongFrame()Send an empty pong frameio.netty.util.concurrent.Future<Void>sendPongFrame(byte[] payload)Send a pong frame with a byte array payload (limited to 125 bytes or fewer).io.netty.util.concurrent.Future<Void>sendPongFrame(io.netty.buffer.ByteBuf payload)Send a pong frame with a ByteBuf payload (limited to 125 bytes or fewer).io.netty.util.concurrent.Future<Void>sendTextFrame(io.netty.buffer.ByteBuf payload, boolean finalFragment, int rsv)Allows sending a text frame with fragmentation or extension bits.io.netty.util.concurrent.Future<Void>sendTextFrame(String message)Send a full text frameio.netty.util.concurrent.Future<Void>sendTextFrame(String payload, boolean finalFragment, int rsv)Allows sending a text frame with fragmentation or extension bits.StringtoString()
-
-
-
Method Detail
-
getUpgradeHeaders
public io.netty.handler.codec.http.HttpHeaders getUpgradeHeaders()
- Specified by:
getUpgradeHeadersin interfaceWebSocket- Returns:
- the headers received in the Upgrade response
-
getRemoteAddress
public SocketAddress getRemoteAddress()
Description copied from interface:WebSocketGet remote address client initiated request to.- Specified by:
getRemoteAddressin interfaceWebSocket- Returns:
- remote address client initiated request to, may be
nullif asynchronous provider is unable to provide the remote address
-
getLocalAddress
public SocketAddress getLocalAddress()
Description copied from interface:WebSocketGet local address client initiated request from.- Specified by:
getLocalAddressin interfaceWebSocket- Returns:
- local address client initiated request from, may be
nullif asynchronous provider is unable to provide the local address
-
sendTextFrame
public io.netty.util.concurrent.Future<Void> sendTextFrame(String message)
Description copied from interface:WebSocketSend a full text frame- Specified by:
sendTextFramein interfaceWebSocket- Parameters:
message- a text payload- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendTextFrame
public io.netty.util.concurrent.Future<Void> sendTextFrame(String payload, boolean finalFragment, int rsv)
Description copied from interface:WebSocketAllows sending a text frame with fragmentation or extension bits. When using fragmentation, the next fragments must be sent with sendContinuationFrame.- Specified by:
sendTextFramein interfaceWebSocket- Parameters:
payload- a text fragment.finalFragment- flag indicating whether this is the final fragmentrsv- extension bits, 0 otherwise- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendTextFrame
public io.netty.util.concurrent.Future<Void> sendTextFrame(io.netty.buffer.ByteBuf payload, boolean finalFragment, int rsv)
Description copied from interface:WebSocketAllows sending a text frame with fragmentation or extension bits. When using fragmentation, the next fragments must be sent with sendContinuationFrame.- Specified by:
sendTextFramein interfaceWebSocket- Parameters:
payload- a ByteBuf fragment.finalFragment- flag indicating whether this is the final fragmentrsv- extension bits, 0 otherwise- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendBinaryFrame
public io.netty.util.concurrent.Future<Void> sendBinaryFrame(byte[] payload)
Description copied from interface:WebSocketSend a full binary frame.- Specified by:
sendBinaryFramein interfaceWebSocket- Parameters:
payload- a binary payload- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendBinaryFrame
public io.netty.util.concurrent.Future<Void> sendBinaryFrame(byte[] payload, boolean finalFragment, int rsv)
Description copied from interface:WebSocketAllows sending a binary frame with fragmentation or extension bits. When using fragmentation, the next fragments must be sent with sendContinuationFrame.- Specified by:
sendBinaryFramein interfaceWebSocket- Parameters:
payload- a binary payloadfinalFragment- flag indicating whether this is the last fragmentrsv- extension bits, 0 otherwise- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendBinaryFrame
public io.netty.util.concurrent.Future<Void> sendBinaryFrame(io.netty.buffer.ByteBuf payload, boolean finalFragment, int rsv)
Description copied from interface:WebSocketAllows sending a binary frame with fragmentation or extension bits. When using fragmentation, the next fragments must be sent with sendContinuationFrame.- Specified by:
sendBinaryFramein interfaceWebSocket- Parameters:
payload- a ByteBuf payloadfinalFragment- flag indicating whether this is the last fragmentrsv- extension bits, 0 otherwise- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendContinuationFrame
public io.netty.util.concurrent.Future<Void> sendContinuationFrame(String payload, boolean finalFragment, int rsv)
Description copied from interface:WebSocketSend a text continuation frame. The last fragment must have finalFragment set to true.- Specified by:
sendContinuationFramein interfaceWebSocket- Parameters:
payload- the text fragmentfinalFragment- flag indicating whether this is the last fragmentrsv- extension bits, 0 otherwise- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendContinuationFrame
public io.netty.util.concurrent.Future<Void> sendContinuationFrame(byte[] payload, boolean finalFragment, int rsv)
Description copied from interface:WebSocketSend a binary continuation frame. The last fragment must have finalFragment set to true.- Specified by:
sendContinuationFramein interfaceWebSocket- Parameters:
payload- the binary fragmentfinalFragment- flag indicating whether this is the last fragmentrsv- extension bits, 0 otherwise- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendContinuationFrame
public io.netty.util.concurrent.Future<Void> sendContinuationFrame(io.netty.buffer.ByteBuf payload, boolean finalFragment, int rsv)
Description copied from interface:WebSocketSend a continuation frame (those are actually untyped as counterpart must have memorized first fragmented frame type). The last fragment must have finalFragment set to true.- Specified by:
sendContinuationFramein interfaceWebSocket- Parameters:
payload- a ByteBuf fragmentfinalFragment- flag indicating whether this is the last fragmentrsv- extension bits, 0 otherwise- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendPingFrame
public io.netty.util.concurrent.Future<Void> sendPingFrame()
Description copied from interface:WebSocketSend an empty ping frame- Specified by:
sendPingFramein interfaceWebSocket- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendPingFrame
public io.netty.util.concurrent.Future<Void> sendPingFrame(byte[] payload)
Description copied from interface:WebSocketSend a ping frame with a byte array payload (limited to 125 bytes or fewer).- Specified by:
sendPingFramein interfaceWebSocket- Parameters:
payload- the payload.- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendPingFrame
public io.netty.util.concurrent.Future<Void> sendPingFrame(io.netty.buffer.ByteBuf payload)
Description copied from interface:WebSocketSend a ping frame with a ByteBuf payload (limited to 125 bytes or fewer).- Specified by:
sendPingFramein interfaceWebSocket- Parameters:
payload- the payload.- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendPongFrame
public io.netty.util.concurrent.Future<Void> sendPongFrame()
Description copied from interface:WebSocketSend an empty pong frame- Specified by:
sendPongFramein interfaceWebSocket- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendPongFrame
public io.netty.util.concurrent.Future<Void> sendPongFrame(byte[] payload)
Description copied from interface:WebSocketSend a pong frame with a byte array payload (limited to 125 bytes or fewer).- Specified by:
sendPongFramein interfaceWebSocket- Parameters:
payload- the payload.- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendPongFrame
public io.netty.util.concurrent.Future<Void> sendPongFrame(io.netty.buffer.ByteBuf payload)
Description copied from interface:WebSocketSend a pong frame with a ByteBuf payload (limited to 125 bytes or fewer).- Specified by:
sendPongFramein interfaceWebSocket- Parameters:
payload- the payload.- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendCloseFrame
public io.netty.util.concurrent.Future<Void> sendCloseFrame()
Description copied from interface:WebSocketSend an empty close frame.- Specified by:
sendCloseFramein interfaceWebSocket- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
sendCloseFrame
public io.netty.util.concurrent.Future<Void> sendCloseFrame(int statusCode, String reasonText)
Description copied from interface:WebSocketSend an empty close frame.- Specified by:
sendCloseFramein interfaceWebSocket- Parameters:
statusCode- a status codereasonText- a reason- Returns:
- a future that will be completed once the frame will be actually written on the wire
-
isOpen
public boolean isOpen()
-
addWebSocketListener
public WebSocket addWebSocketListener(WebSocketListener l)
Description copied from interface:WebSocketAdd aWebSocketListener- Specified by:
addWebSocketListenerin interfaceWebSocket- Parameters:
l- aWebSocketListener- Returns:
- this
-
removeWebSocketListener
public WebSocket removeWebSocketListener(WebSocketListener l)
Description copied from interface:WebSocketRemove aWebSocketListener- Specified by:
removeWebSocketListenerin interfaceWebSocket- Parameters:
l- aWebSocketListener- Returns:
- this
-
isReady
public boolean isReady()
-
bufferFrame
public void bufferFrame(io.netty.handler.codec.http.websocketx.WebSocketFrame frame)
-
processBufferedFrames
public void processBufferedFrames()
-
handleFrame
public void handleFrame(io.netty.handler.codec.http.websocketx.WebSocketFrame frame)
-
onError
public void onError(Throwable t)
-
onClose
public void onClose(int code, String reason)
-
-