Which is the correct/current websockets handshake?

I’m writing a websocket client for NETMF, and I’m trying to implement the handshaking protocol. I’ve read RFC6455, and I’ve also looked at 10 or more open source implementations of websocket clients, and I see two different implementations of the handshaking protocol.

RFC6455:
The handshake from the client looks as follows:

    GET /chat HTTP/1.1
    Host: server.example.com
    Upgrade: websocket
    Connection: Upgrade
    Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
    Origin: http://example.com
    Sec-WebSocket-Protocol: chat, superchat
    Sec-WebSocket-Version: 13

The handshake from the server looks as follows:

    HTTP/1.1 101 Switching Protocols
    Upgrade: websocket
    Connection: Upgrade
    Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
    Sec-WebSocket-Protocol: chat

Open Source Examples:
The handshake from the client looks as follows:

    GET /demo HTTP/1.1
    Host: example.com
    Connection: Upgrade
    Sec-WebSocket-Key2: 12998 5 Y3 1  .P00
    Sec-WebSocket-Protocol: sample
    Upgrade: WebSocket
    Sec-WebSocket-Key1: 4 @ 1  46546xW%0l 1 5
    Origin: http://example.com

    ^n:ds[4U

The handshake from the server looks as follows:

    HTTP/1.1 101 WebSocket Protocol Handshake
    Upgrade: WebSocket
    Connection: Upgrade
    Sec-WebSocket-Origin: http://example.com
    Sec-WebSocket-Location: ws://example.com/demo
    Sec-WebSocket-Protocol: sample

    8jKS'y:G*Co,Wxa-

Did you take a look at Andre.M’s implementation?
http://www.tinyclr.com/codeshare/entry/616

Yes, I did. His code parses the websocket data frame, but does not deal with the initial connection handshake.

@ jasdev - to support most current browsers your should implement HyBi09 and Hixy76

@ andre.m - I implemented both protocols about a year ago, just recently updated Hybi to have it work with the latest chrome. I just did a quick check and noticed that hixy is still used by Safari on iPad1 (iOS 5.1.1)

@ andre.m - Thanks for the update !!

andre.m and RobvanSchelven - thank you very much.

I also read that RFC6455 has been finalized, and is the current standard to implement. The thing that threw me off was that almost all open source implementations I found implement the earlier standards.

andre.m - thank you for the code snippet. I was implementing something similar, but your’s is better!

I’m using the Cobra 1 with ver 4.2. I’m doing most of my development on the desktop with full .NET, but I have a VS solution that contains multiple projects, including a “Core” project for full .NET and a “Core” project for NETMF. I am trying to have as much common code as possible, and I also link as many files as I can between projects instead of copying them. My goal is to develop a WinForm websocket client and server for testing and debugging, and a NETMF cllent and server for eventual deployment.

I like this approach… develop with full .NET,… then port to .NETMF. I am careful to use name spaces, classes, and methods that are common to both libraries whenever possible.

What board are you developing for?

Yes, I’m glad to help.

andre - I’m at work now. I work for a financial company, and they are really strict about security, so I can’t send a personal email from here. I’ll send an email when I get home tonight. Oh, and believe it or not, I don’t own a smart phone, so I can’t use that either :slight_smile: