1

I've spent some time trawling through stack overflow and google, but alas I was unable to find the what I've been looking for (there may be something I've missed, sorry if there is). This is driving me insane as I'm so certain it all looks right, but obviously something is wrong and I just can't see it.

Basically, the handshake is fine. I receive and parse packets from the client fine.

When I try to send framed packet data back to the client, the client does nothing (not even an error). I've tried it on the latest Firefox and Chrome browsers using the example on echo.websocket.org and my own written javascript object. I can see the packet being sent and received via Wireshark on both the client and the server.

Here is an example of what I'm sending and a breakdown of the packet according to the RFC 6455 standards.

        Entire Response Packet Sent : 
            00 16 d3 65 d0 50 f4 6d 
            04 00 5f 84 08 00 45 00 
            00 32 5f e3 40 00 80 06 
            17 8c c0 a8 01 02 c0 a8 
            01 04 1f 91 05 18 fd 56 
            6f 03 ea 17 6d 4c 50 18 
            01 00 c0 fa 00 00 81 84 
            b2 3f de 11 83 0d ed 25

        Payload Data Unmasked Should Read : 1234

        Data : 
            81 84 B2 3F DE 11 83 0D ED 25

            FIN, RSV 1-3 and Op Code :

            0x81    1000 0001
                FIN     1 
                RSV1    0
                RSV2    0
                RSV3    0
                Opcode  1

            Mask and Payload Length :

            0x84    1000 0100
                Mask    1
                Length  4

            Mask Key :

            0xB2    1011 0010
            0x3F    0011 1111
            0xDE    1101 1110
            0x11    0001 0001

            Masked Payload Data : 

            0x83    1000 0011
            0x0D    0000 1101
            0xED    1110 1101
            0x25    0010 0101

            Unmasked Data

            Binary          Decimal         Hex         UTF-8

            1011 0010  
            1000 0011 ^
            -----------
            0011 0001       49              31          1

            0011 1111 
            0000 1101 ^
            -----------
            0011 0010       50              32          2

            1101 1110
            1110 1101 ^
            -----------
            0011 0011       51              33          3

            0001 0001 
            0010 0101 ^
            -----------
            0011 0100       52              34          4

My entire codebase is on GitHub, but here are the core files :

Data Frame Structure : https://github.com/willitscale/simplejavawebsocket/blob/master/java/src/uk/co/n3tw0rk/websocketregistration/framing/DataFrame.java

Data Frame Response Builder : https://github.com/willitscale/simplejavawebsocket/blob/master/java/src/uk/co/n3tw0rk/websocketregistration/framing/DataFrameResponse.java

Client Socket Connection Thread : https://github.com/willitscale/simplejavawebsocket/blob/master/java/src/uk/co/n3tw0rk/websocketregistration/threads/SocketClient.java

Whole repository : https://github.com/willitscale/simplejavawebsocket

Any help would be much appreciated!

5
  • 1
    Since you seem to still be on the RFC-6455 protocol part of the spec, get yourself a copy of the official RFC-6455 protocol testsuite (autobahn testsuite) autobahn.ws/testsuite - test your code against it, you will be able to find your problems quickly enough, and be sure that your code works against the same protocol testsuite that Chrome / Jetty / Tomcat / Apache / Firefox / MSIE use. Commented Dec 4, 2013 at 18:24
  • You wouldn't happen to know if there was any documentation for this Autobahn Test Suite would you? I've got it up and working and I'm getting errors in the Wire section, but it's not exactly clear what the errors are. Commented Dec 5, 2013 at 19:45
  • The details in the reports show what was sent/received in multiple ways. (as a unmasked frame + raw octets on the network). See the "Case Outcome" section too for what was expected. Commented Dec 5, 2013 at 21:01
  • Start with addressing the simple test case failures, consult RFC-6455 often. The details on what is going on, and what is expected are in the reports. Feel free to ask specific (new) questions about websocket. Commented Dec 5, 2013 at 21:03
  • In your case, start the autobahn fuzzing server, then write a special autobahn test client with your library to test it. Here's an example of one jetty-autobahn-websocket-client Commented Dec 5, 2013 at 21:05

2 Answers 2

2

A bit more detail on wiring up your WebSocket client library to the autobahn websocket protocol testsuite.

  1. Create a spec for yourself fuzzingserver.json
{
   "url": "ws://127.0.0.1:9001",

   "options": {"failByDrop": false},
   "outdir": "./reports/clients",
   "webport": 8080,

   "cases": ["*"],
   "exclude-cases": [],
   "exclude-agent-cases": {}
}

This file allows you to tweak what test cases should be run, what your port numbers are, etc .

  1. Start the autobahn fuzzing server

    $ wstest -m fuzzingserver

  2. In your client code

    A: Request the number of cases.

    ws://localhost:9001/getCaseCount

    You will receive a TEXT message, an Integer representing the number of test cases

    B: Connect and run specific test case (by number)

    ws://localhost:9001/runCase?case={case_number}&agent={library-name}

    Be sure to echo back any complete TEXT or BINARY messages received to the server.

    C: Generate the Reports

    ws://localhost:9001/updateReports?agent={library-name}

You should now have a report of the testcases you ran on disk, in the path you specified in the fuzzingserver.json above

Sign up to request clarification or add additional context in comments.

1 Comment

I don't believe it's anything to do with websockets at all I believe it's a TCP issue or networking issue. Neither the browsers or Autobahn seem to be receiving the packet even though I can see it as clear as day on both ends in Wireshark. When I test other websocket servers it's fine inside the TCP packet I can see : [Protocols in frame: eth:ip:tcp:http:websocket] in my packets I'm getting : [Protocols in frame: eth:ip:tcp:http] Time for some network and TCP packet analysis
0

Finally got to the bottom of it!

Although the handshake appeared to work it actually screwed up the buffer on the client.

My response to the client was a half and half, half from the RFC6455 and half from HYBI standards where the handshake key was in the body of the response.

This is just a theory and I've not looked into it but I believe it stopped reading the buffer after the "\r\n\r\n", when I sent a message the first thing it must of read was the accept key left over from the buffer the first time.

            "Sec-WebSocket-Accept: " + Utils.generateKey( wsrRequest.socketKey ) + "\r\n" +
            "\r\n" + Utils.generateKey( wsrRequest.socketKey );

Thanks for all your help, never fear it will not be in vein as you've opened my eyes to Autobahn Test Suite!

Curious though Autobahn didn't pick this issue with the handshake up, nor did chrome or firebug? A bug perhaps?

Why is it always me who finds these kinds of things /sigh

Last week it was an actual bug with a payment service after days of investigating and thinking I was wrong, it was the service that didn't do what the documentation said. Luckily in this cause I was wrong!

Either way, onward and upward I can finally continue my development. After about a day and half set back while I was convinced that java was screwing up the bytes, tcp packets or Websockets would only work on a non-blocking full duplex socket connection and not a half duplex socket connection.

I'm my own worst enemy

1 Comment

AutobahnTestsuite has hundreds of tests for all sections of RFC6455, however the opening handshake is not yet tested. This is mentioned on the front page of the testsuite under coverage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.