0

I'm working with NodeJS and found this code that implements kind of native support for sockets since NodeJS doesn't supports sockets by default.

So I used the code to open a server(server is waiting...), now for the client side I used some simple html file on my desktop with code like that, well at first glance it fail, but when I debug the code a bit I found out the the NodeJS socket code I found needs sec-websocket-key1 and sec-websocket-key2 while I get from the client-side code I implemented(in the plnkr) only sec-websocket-key.

I looked that up and found that link that saying:

The first protocol used by HTML5 WebSockets was draft-ietf-hybi-thewebsocketprotocol-00 (HyBi 00). All was well until the protocol was upgraded to remedy some security issues. As a result of these changes, the Sec-WebSocket-Key1 and Sec-WebSocket-Key2 fields were added to the client header.

Basically that explains why I get sec-websocket-key, I know that article also say that(according to caniuse) there only 2 browser supports the latest websockets protocol, I tested with chrome and firefox and both sends the same sec-websocket-key...

  • What is the true protocol I should support(is the right one), the one used web-socket-key1/2 or just sec-websocket-key
  • Which browsers supports(if those should be supported) sec-websocket-key1 and sec-websocket-key2?
  • Am I doing something entirely wrong with my client-side Web Sockets or the server side?
  • Is there a shim to fix something?
Aviel Fedida
  • 4,004
  • 9
  • 54
  • 88

1 Answers1

2

The article is several years old and describes version 6 of the protocol, which was still only a draft is now long obsolete. The current version is 13 and is described in RFC 6455. And this is the version you will find implemented in all current browsers.

Thus it is best to simply ignore the article or only see it in a historical context. For any new implementation please refer to the RFC only and not to any previous drafts.

I know that article also say that(according to caniuse) there only 2 browser supports the latest websockets protocol,

Looking at caniuse shows that all current browsers support the relevant version of Websockets.

since NodeJS doesn't supports sockets by default.

This question from 2013 has an overview of several implementations. I'm pretty sure that widely used implementations like Socket.IO support the latest version of the protocol.


Community
  • 1
  • 1
Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172