Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket failed: One or more reserved bits are on #61

Closed
sunnygoyal opened this issue Aug 30, 2013 · 3 comments
Closed

Websocket failed: One or more reserved bits are on #61

sunnygoyal opened this issue Aug 30, 2013 · 3 comments

Comments

@sunnygoyal
Copy link

I am running the server on android and trying to connect to it from macbook on same network.

Getting the following error on chrome and firefox:
WebSocket connection to 'ws://192.168.0.102:8888/echo' failed: One or more reserved bits are on: reserved1 = 1, reserved2 = 0, reserved3 = 0

Firefox:
[21:25:49.381] The connection to ws://192.168.0.102:8888/echo was interrupted while the page was loading. @ http://192.168.0.102:8888/:7

Server code

    mServer = new AsyncHttpServer();
    mServer.get("/", new HttpServerRequestCallback() {
      @Override
      public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
        response.send(readStream(getResources().openRawResource(R.raw.index)));
      }
    });
    mServer.websocket("/echo", new WebSocketRequestCallback() {

      @Override
      public void onConnected(WebSocket webSocket, RequestHeaders headers) {
        webSocket.setStringCallback(new StringCallback() {

          @Override
          public void onStringAvailable(String s) {
            Log.e("Socket", "msg : " + s);
          }
        });
      }
    });

    mServer.listen(8888);

index.html

<html>
<head>
<title>Web Socket test</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function initws() {
    var connection = new WebSocket('ws://192.168.0.102:8888/echo', "chat");

    // When the connection is open, send some data to the server
    connection.onopen = function () {
        console.log('connected'); // Send the message 'Ping' to the server
    };

    // Log errors
    connection.onerror = function (error) {
      console.log('WebSocket Error', error);
    };

    // Log messages from the server
    connection.onmessage = function (e) {
      console.log("Message", e);
    };
}
</script>
</head>
<body>
<h1>Web Socket test</h1>
<button onclick="initws()">Connect</button>

Update:
Same error on chrome on android itself, so it should not be a firewall issue.
Also the error happens just after onopen as I am getting the 'connected' message. And if I send some message back from index.html in onopen, it is received by the server

@koush
Copy link
Owner

koush commented Aug 30, 2013

Are you using the master branch or something older?

@sunnygoyal
Copy link
Author

I am using the master branch

@koush
Copy link
Owner

koush commented Aug 30, 2013

Fixed a couple issues. First, websocket headers were being written twice:

4a5a55b

The websocket server needs to support protocols (like "chat") in your example:

9fac4cb

AsyncHttpClient.getDefaultInstance()
.websocket("http://192.168.1.2:3005", "chat", new WebSocketConnectCallback() {...

@koush koush closed this as completed Aug 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants