Draft refuses handshake when using java-websocket library to connect to the coinbase exchange websocket stream : <p>I am attempting to use the <a href="https://github.com/TooTallNate/Java-WebSocket" rel="noreferrer">Java-Websocket library by TooTallNate</a> to create a websocket client that receives messages from the <a href="https://docs.exchange.coinbase.com/" rel="noreferrer">coinbase exchange websocket stream</a>. I am porting a program I made in Python to Java because of parallelisation bottlenecks in Python and to my knowledge I am doing things the same in Java as I did in Python. Here is my code to open the connection in Python using <a href="https://github.com/liris/websocket-client" rel="noreferrer">this websocket lib</a> (This works as expected):</p>

<pre><code>ws = websocket.create_connection("wss://ws-feed.exchange.coinbase.com", 20)
            ws.send(json.dumps({
            "type": "subscribe",
            "product_id": "BTC-USD"
        }))
</code></pre>

<p>Here is my entire Java class:</p>

<pre><code>public class CoinbaseWebsocketClient extends WebSocketClient {

private final Gson gson = new Gson();

private CoinbaseWebsocketClient(URI serverURI) {
    super(serverURI, new Draft_17());
    connect();
}

private static URI uri;
private static CoinbaseWebsocketClient coinbaseWebsocketClient;

static {
    try {
        uri = new URI("wss://ws-feed.exchange.coinbase.com");
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

protected static CoinbaseWebsocketClient get() {
    if (coinbaseWebsocketClient == null) {
        coinbaseWebsocketClient = new CoinbaseWebsocketClient(uri);
    }
    return coinbaseWebsocketClient;
}

@Override
public void onOpen(ServerHandshake serverHandshake) {
    System.out.println("Websocket open");
    final JsonObject btcUSD_Request = new JsonObject();
    btcUSD_Request.addProperty("type", "subscribe");
    btcUSD_Request.addProperty("product_id", "BTC_USD");
    final String requestString = gson.toJson(btcUSD_Request);
    send(requestString);
}

@Override
public void onMessage(String s) {
    System.out.println("Message received: " + s);
}

@Override
public void onClose(int code, String reason, boolean remote) {
    System.out.println("Websocket closed: " + reason);
}

@Override
public void onError(Exception e) {
    System.err.println("an error occurred:" + e);
}
</code></pre>

<p>}</p>

<p>I know there isn't a totally fundamental issue with my Java code because it works as expected when I use ws://echo.websocket.org as the URI instead of wss://ws-feed.exchange.coinbase.com. However when I try to connect to wss://ws-feed.exchange.coinbase.com I get this error:</p>

<pre><code>Websocket closed: draft org.java_websocket.drafts.Draft_17@7ca2fefb refuses handshake
</code></pre>

<p>There is no authentication or anything like for this connection as far as I know (I didn't provide any in my Python program) so I'm at a loss as to what the source of this error is.</p>
