/** * Send a ping frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createPingFrame() createPingFrame()}). * </p> * * @return * {@code this} object. */ public WebSocket sendPing() { return sendFrame(WebSocketFrame.createPingFrame()); }
/** * Send a close frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createCloseFrame() createCloseFrame()}). * </p> * * @return * {@code this} object. */ public WebSocket sendClose() { return sendFrame(WebSocketFrame.createCloseFrame()); }
/** * Send a pong frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createPongFrame() createPongFrame()}). * </p> * * @return * {@code this} object. */ public WebSocket sendPong() { return sendFrame(WebSocketFrame.createPongFrame()); }
/** * Send a ping frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createPingFrame(String) * createPingFrame}{@code (payload))}. * </p> * * @param payload * The payload for a ping frame. * Note that a control frame's payload length must be 125 bytes or less * (RFC 6455, <a href="https://tools.ietf.org/html/rfc6455#section-5.5" * >5.5. Control Frames</a>). * * @return * {@code this} object. */ public WebSocket sendPing(String payload) { return sendFrame(WebSocketFrame.createPingFrame(payload)); }
/** * Send a pong frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createPongFrame(byte[]) * createPongFrame}{@code (payload))}. * </p> * * @param payload * The payload for a pong frame. * Note that a control frame's payload length must be 125 bytes or less * (RFC 6455, <a href="https://tools.ietf.org/html/rfc6455#section-5.5" * >5.5. Control Frames</a>). * * @return * {@code this} object. */ public WebSocket sendPong(byte[] payload) { return sendFrame(WebSocketFrame.createPongFrame(payload)); }
/** * Send a close frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createCloseFrame(int) * createCloseFrame}{@code (closeCode))}. * </p> * * @param closeCode * The close code. * * @return * {@code this} object. * * @see WebSocketCloseCode */ public WebSocket sendClose(int closeCode) { return sendFrame(WebSocketFrame.createCloseFrame(closeCode)); }
/** * Send a continuation frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createContinuationFrame() * createContinuationFrame()}{@code )}. * </p> * * <p> * Note that the FIN bit of a frame sent by this method is {@code false}. * If you want to set the FIN bit, use {@link #sendContinuation(boolean) * sendContinuation(boolean fin)} with {@code fin=true}. * </p> * * @return * {@code this} object. */ public WebSocket sendContinuation() { return sendFrame(WebSocketFrame.createContinuationFrame()); }
/** * Send a ping frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createPingFrame(byte[]) * createPingFrame}{@code (payload))}. * </p> * * @param payload * The payload for a ping frame. * Note that a control frame's payload length must be 125 bytes or less * (RFC 6455, <a href="https://tools.ietf.org/html/rfc6455#section-5.5" * >5.5. Control Frames</a>). * * @return * {@code this} object. */ public WebSocket sendPing(byte[] payload) { return sendFrame(WebSocketFrame.createPingFrame(payload)); }
/** * Send a pong frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createPongFrame(String) * createPongFrame}{@code (payload))}. * </p> * * @param payload * The payload for a pong frame. * Note that a control frame's payload length must be 125 bytes or less * (RFC 6455, <a href="https://tools.ietf.org/html/rfc6455#section-5.5" * >5.5. Control Frames</a>). * * @return * {@code this} object. */ public WebSocket sendPong(String payload) { return sendFrame(WebSocketFrame.createPongFrame(payload)); }
/** * Send a binary message to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createBinaryFrame(byte[]) * createBinaryFrame}{@code (message))}. * </p> * * <p> * If you want to send a binary frame that is to be followed by * continuation frames, use {@link #sendBinary(byte[], boolean) * setBinary(byte[] payload, boolean fin)} with {@code fin=false}. * </p> * * @param message * A binary message to be sent to the server. * * @return * {@code this} object. */ public WebSocket sendBinary(byte[] message) { return sendFrame(WebSocketFrame.createBinaryFrame(message)); }
/** * Send a text message to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createTextFrame(String) * createTextFrame}{@code (message))}. * </p> * * <p> * If you want to send a text frame that is to be followed by * continuation frames, use {@link #sendText(String, boolean) * setText(String payload, boolean fin)} with {@code fin=false}. * </p> * * @param message * A text message to be sent to the server. * * @return * {@code this} object. */ public WebSocket sendText(String message) { return sendFrame(WebSocketFrame.createTextFrame(message)); }
/** * Send a close frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createCloseFrame(int, String) * createCloseFrame}{@code (closeCode, reason))}. * </p> * * @param closeCode * The close code. * * @param reason * The close reason. * Note that a control frame's payload length must be 125 bytes or less * (RFC 6455, <a href="https://tools.ietf.org/html/rfc6455#section-5.5" * >5.5. Control Frames</a>). * * @return * {@code this} object. * * @see WebSocketCloseCode */ public WebSocket sendClose(int closeCode, String reason) { return sendFrame(WebSocketFrame.createCloseFrame(closeCode, reason)); }
/** * Send a continuation frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createContinuationFrame() * createContinuationFrame()}{@code .}{@link * WebSocketFrame#setFin(boolean) setFin}{@code (fin))}. * </p> * * @param fin * The FIN bit value. * * @return * {@code this} object. */ public WebSocket sendContinuation(boolean fin) { return sendFrame(WebSocketFrame.createContinuationFrame().setFin(fin)); }
/** * Send a text frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createTextFrame(String) * createTextFrame}{@code (payload).}{@link * WebSocketFrame#setFin(boolean) setFin}{@code (fin))}. * </p> * * @param payload * The payload of a text frame. * * @param fin * The FIN bit value. * * @return * {@code this} object. */ public WebSocket sendText(String payload, boolean fin) { return sendFrame(WebSocketFrame.createTextFrame(payload).setFin(fin)); }
/** * Send a continuation frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createContinuationFrame(String) * createContinuationFrame}{@code (payload).}{@link * WebSocketFrame#setFin(boolean) setFin}{@code (fin))}. * </p> * * @param payload * The payload of a continuation frame. * * @param fin * The FIN bit value. * * @return * {@code this} object. */ public WebSocket sendContinuation(String payload, boolean fin) { return sendFrame(WebSocketFrame.createContinuationFrame(payload).setFin(fin)); }
/** * Send a continuation frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createContinuationFrame(byte[]) * createContinuationFrame}{@code (payload).}{@link * WebSocketFrame#setFin(boolean) setFin}{@code (fin))}. * </p> * * @param payload * The payload of a continuation frame. * * @param fin * The FIN bit value. * * @return * {@code this} object. */ public WebSocket sendContinuation(byte[] payload, boolean fin) { return sendFrame(WebSocketFrame.createContinuationFrame(payload).setFin(fin)); }
/** * Send a binary frame to the server. * * <p> * This method is an alias of {@link #sendFrame(WebSocketFrame) * sendFrame}{@code (WebSocketFrame.}{@link * WebSocketFrame#createBinaryFrame(byte[]) * createBinaryFrame}{@code (payload).}{@link * WebSocketFrame#setFin(boolean) setFin}{@code (fin))}. * </p> * * @param payload * The payload of a binary frame. * * @param fin * The FIN bit value. * * @return * {@code this} object. */ public WebSocket sendBinary(byte[] payload, boolean fin) { return sendFrame(WebSocketFrame.createBinaryFrame(payload).setFin(fin)); }
private boolean handlePingFrame(WebSocketFrame frame) { // Notify the listeners that a ping frame was received. callOnPingFrame(frame); // RFC 6455, 5.5.3. Pong // // A Pong frame sent in response to a Ping frame must // have identical "Application data" as found in the // message body of the Ping frame being replied to. // Create a pong frame which has the same payload as // the ping frame. WebSocketFrame pong = WebSocketFrame .createPongFrame(frame.getPayload()); // Send the pong frame to the server. mWebSocket.sendFrame(pong); // Keep reading. return true; }
private void doTask() { synchronized (this) { if (mInterval == 0 || mWebSocket.isOpen() == false) { mScheduled = false; // Not schedule a new task. return; } // Create a frame and send it to the server. mWebSocket.sendFrame(createFrame()); // Schedule a new task. mScheduled = schedule(mTimer, new Task(), mInterval); } }
private byte[] decompress(byte[] input) { WebSocketException wse; try { // Decompress the message. return mPMCE.decompress(input); } catch (WebSocketException e) { wse = e; } // Notify the listeners that decompression failed. callOnError(wse); callOnMessageDecompressionError(wse, input); // Create a close frame with a close code of 1003 which // indicates that the message cannot be accepted. WebSocketFrame frame = WebSocketFrame .createCloseFrame(WebSocketCloseCode.UNACCEPTABLE, wse.getMessage()); // Send the close frame. mWebSocket.sendFrame(frame); // Failed to construct a message. return null; }