diff --git a/src/main/java/com/neovisionaries/ws/client/WebSocket.java b/src/main/java/com/neovisionaries/ws/client/WebSocket.java index 2b03df8..1272d89 100644 --- a/src/main/java/com/neovisionaries/ws/client/WebSocket.java +++ b/src/main/java/com/neovisionaries/ws/client/WebSocket.java @@ -1091,6 +1091,7 @@ */ public class WebSocket { + public static boolean useMask = true; private static final long DEFAULT_CLOSE_DELAY = 10 * 1000L; private final WebSocketFactory mWebSocketFactory; private final SocketConnector mSocketConnector; diff --git a/src/main/java/com/neovisionaries/ws/client/WebSocketOutputStream.java b/src/main/java/com/neovisionaries/ws/client/WebSocketOutputStream.java index 670304c..58ad171 100644 --- a/src/main/java/com/neovisionaries/ws/client/WebSocketOutputStream.java +++ b/src/main/java/com/neovisionaries/ws/client/WebSocketOutputStream.java @@ -44,14 +44,17 @@ public void write(WebSocketFrame frame) throws IOException writeFrame1(frame); writeFrameExtendedPayloadLength(frame); - // Generate a random masking key. - byte[] maskingKey = Misc.nextBytes(4); - // Write the masking key. - write(maskingKey); - - // Write the payload. - writeFramePayload(frame, maskingKey); + if (WebSocket.useMask) { + // Generate a random masking key. + byte[] maskingKey = Misc.nextBytes(4); + write(maskingKey); + + // Write the payload. + writeFramePayload(frame, maskingKey); + } else { + writeFramePayload(frame, null); + } } @@ -70,7 +73,12 @@ private void writeFrame0(WebSocketFrame frame) throws IOException private void writeFrame1(WebSocketFrame frame) throws IOException { // Frames sent from a client are always masked. - int b = 0x80; + int b; + if (WebSocket.useMask) { + b = 0x80; + } else { + b = 0x00; + } int len = frame.getPayloadLength(); @@ -133,7 +141,12 @@ private void writeFramePayload(WebSocketFrame frame, byte[] maskingKey) throws I for (int i = 0; i < payload.length; ++i) { // Mask - int b = (payload[i] ^ maskingKey[i % 4]) & 0xFF; + int b; + if (WebSocket.useMask) { + b = (payload[i] ^ maskingKey[i % 4]) & 0xFF; + } else { + b = (payload[i]) & 0xFF; + } // Write write(b);