220 * <p> A {@code WebSocket} invokes methods on the associated listener |
220 * <p> A {@code WebSocket} invokes methods on the associated listener |
221 * passing itself as an argument. |
221 * passing itself as an argument. |
222 * |
222 * |
223 * <p> Messages received by the listener either conform to the WebSocket |
223 * <p> Messages received by the listener either conform to the WebSocket |
224 * Protocol, or {@code onError} with an {@link IOException} is invoked. |
224 * Protocol, or {@code onError} with an {@link IOException} is invoked. |
225 * Any {@code IOException} occurred in {@code WebSocket} will result in an |
225 * An {@code IOException} raised in {@code WebSocket} will result in an |
226 * invocation of {@code onError} with that exception. Unless otherwise |
226 * invocation of {@code onError} with that exception, if the input is not |
227 * stated if the listener's method throws an exception or a |
227 * closed. Unless otherwise stated if the listener's method throws an |
228 * {@code CompletionStage} returned from a method completes exceptionally, |
228 * exception or a {@code CompletionStage} returned from a method completes |
229 * the WebSocket will invoke {@code onError} with this exception. |
229 * exceptionally, the WebSocket will invoke {@code onError} with this |
|
230 * exception. |
230 * |
231 * |
231 * <p> If a listener's method returns {@code null} rather than a |
232 * <p> If a listener's method returns {@code null} rather than a |
232 * {@code CompletionStage}, {@code WebSocket} will behave as if the listener |
233 * {@code CompletionStage}, {@code WebSocket} will behave as if the listener |
233 * returned a {@code CompletionStage} that is already completed normally. |
234 * returned a {@code CompletionStage} that is already completed normally. |
234 * |
235 * |
410 * been closed. |
411 * been closed. |
411 * |
412 * |
412 * <p> A Close message consists of a status code and a reason for |
413 * <p> A Close message consists of a status code and a reason for |
413 * closing. The status code is an integer from the range |
414 * closing. The status code is an integer from the range |
414 * {@code 1000 <= code <= 65535}. The {@code reason} is a string which |
415 * {@code 1000 <= code <= 65535}. The {@code reason} is a string which |
415 * has an UTF-8 representation not longer than {@code 123} bytes. |
416 * has a UTF-8 representation not longer than {@code 123} bytes. |
416 * |
417 * |
417 * <p> If the WebSocket's output is not already closed, the |
418 * <p> If the WebSocket's output is not already closed, the |
418 * {@code CompletionStage} returned by this method will be used as an |
419 * {@code CompletionStage} returned by this method will be used as an |
419 * indication that the WebSocket's output may be closed. The WebSocket |
420 * indication that the WebSocket's output may be closed. The WebSocket |
420 * will close its output at the earliest of completion of the returned |
421 * will close its output at the earliest of completion of the returned |
477 */ |
478 */ |
478 default void onError(WebSocket webSocket, Throwable error) { } |
479 default void onError(WebSocket webSocket, Throwable error) { } |
479 } |
480 } |
480 |
481 |
481 /** |
482 /** |
482 * Sends a textual data with characters from the given character sequence. |
483 * Sends textual data with characters from the given character sequence. |
483 * |
484 * |
484 * <p> The character sequence must not be modified until the |
485 * <p> The character sequence must not be modified until the |
485 * {@code CompletableFuture} returned from this method has completed. |
486 * {@code CompletableFuture} returned from this method has completed. |
486 * |
487 * |
487 * <p> A {@code CompletableFuture} returned from this method can |
488 * <p> A {@code CompletableFuture} returned from this method can |
507 * when the data has been sent |
508 * when the data has been sent |
508 */ |
509 */ |
509 CompletableFuture<WebSocket> sendText(CharSequence data, boolean last); |
510 CompletableFuture<WebSocket> sendText(CharSequence data, boolean last); |
510 |
511 |
511 /** |
512 /** |
512 * Sends a binary data with bytes from the given buffer. |
513 * Sends binary data with bytes from the given buffer. |
513 * |
514 * |
514 * <p> The data is located in bytes from the buffer's position to its limit. |
515 * <p> The data is located in bytes from the buffer's position to its limit. |
515 * Upon normal completion of a {@code CompletableFuture} returned from this |
516 * Upon normal completion of a {@code CompletableFuture} returned from this |
516 * method the buffer will have no remaining bytes. The buffer must not be |
517 * method the buffer will have no remaining bytes. The buffer must not be |
517 * accessed until after that. |
518 * accessed until after that. |
601 * |
602 * |
602 * <p> The {@code statusCode} is an integer from the range |
603 * <p> The {@code statusCode} is an integer from the range |
603 * {@code 1000 <= code <= 4999}. Status codes {@code 1002}, {@code 1003}, |
604 * {@code 1000 <= code <= 4999}. Status codes {@code 1002}, {@code 1003}, |
604 * {@code 1006}, {@code 1007}, {@code 1009}, {@code 1010}, {@code 1012}, |
605 * {@code 1006}, {@code 1007}, {@code 1009}, {@code 1010}, {@code 1012}, |
605 * {@code 1013} and {@code 1015} are illegal. Behaviour in respect to other |
606 * {@code 1013} and {@code 1015} are illegal. Behaviour in respect to other |
606 * status codes is implementation-specific. The {@code reason} is a string |
607 * status codes is implementation-specific. A legal {@code reason} is a |
607 * that has an UTF-8 representation not longer than {@code 123} bytes. |
608 * string that has a UTF-8 representation not longer than {@code 123} bytes. |
608 * |
609 * |
609 * <p> A {@code CompletableFuture} returned from this method can |
610 * <p> A {@code CompletableFuture} returned from this method can |
610 * complete exceptionally with: |
611 * complete exceptionally with: |
611 * <ul> |
612 * <ul> |
612 * <li> {@link IllegalArgumentException} - |
613 * <li> {@link IllegalArgumentException} - |