Package com.microsoft.azure.relay
Class WebSocketChannel
java.lang.Object
com.microsoft.azure.relay.WebSocketChannel
- All Implemented Interfaces:
HybridConnectionChannel,Closeable,AutoCloseable,Channel
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the websocket connection.Closes the connection with the remote websocketcloseAsync(javax.websocket.CloseReason reason) Closes the connection with the remote websocket with a given CloseReasonbooleanisOpen()Checks whether the websocket connection is still open.Receives byte messages from the remote sender asynchronously.Receives byte messages from the remote sender asynchronously within a given timeout.Receives text messages asynchronously.writeAsync(ByteBuffer data) Sends the data to the remote endpoint as binary.writeAsync(ByteBuffer data, Duration timeout) Sends the data to the remote endpoint within a timeout as binary.writeTextAsync(String textData, Duration timeout) Sends the text data to the remote endpoint within a timeout in one of the WriteModes.
-
Method Details
-
getTrackingContext
- Specified by:
getTrackingContextin interfaceHybridConnectionChannel
-
isOpen
public boolean isOpen()Checks whether the websocket connection is still open. -
close
Closes the websocket connection. Blocks until the connection is completely closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
closeAsync
Closes the connection with the remote websocket- Specified by:
closeAsyncin interfaceHybridConnectionChannel- Returns:
- Returns a CompletableFuture which completes when the connection is completely closed.
-
closeAsync
Closes the connection with the remote websocket with a given CloseReason- Specified by:
closeAsyncin interfaceHybridConnectionChannel- Parameters:
reason- The CloseReason to be given for this operation. For details please see javax.websocket.CloseReason.- Returns:
- Returns a CompletableFuture which completes when the connection is completely closed.
-
readTextAsync
Receives text messages asynchronously.- Returns:
- Returns a CompletableFuture which completes when websocket receives text messages.
-
readAsync
Receives byte messages from the remote sender asynchronously.- Specified by:
readAsyncin interfaceHybridConnectionChannel- Returns:
- Returns a CompletableFuture of the bytes which completes when websocket receives the entire message.
-
readAsync
Receives byte messages from the remote sender asynchronously within a given timeout.- Specified by:
readAsyncin interfaceHybridConnectionChannel- Parameters:
timeout- The timeout duration for this operation.- Returns:
- Returns a CompletableFuture of the bytes which completes when websocket receives the entire message.
-
writeAsync
Sends the data to the remote endpoint as binary.- Specified by:
writeAsyncin interfaceHybridConnectionChannel- Parameters:
data- Message to be sent.- Returns:
- A CompletableFuture which completes when websocket finishes sending the bytes.
-
writeAsync
Sends the data to the remote endpoint within a timeout as binary.- Specified by:
writeAsyncin interfaceHybridConnectionChannel- Parameters:
data- Message to be sent.timeout- The timeout to connect to send the data within. May be null to indicate no timeout limit.- Returns:
- A CompletableFuture which completes when websocket finishes sending the bytes.
-
writeTextAsync
Sends the text data to the remote endpoint within a timeout in one of the WriteModes.- Parameters:
textData- Text message to be sent.timeout- The timeout to connect to send the data within. May be null to indicate no timeout limit.- Returns:
- A CompletableFuture which completes when websocket finishes sending the data.
-