1

I am trying to implement WebSocket with php. And on my desktop computer It works correctly. But when I try to open my website on an android device. My server implementation gives the error below while handshaking.

Undefined index: Sec-WebSocket-Key

Then I checked the values. When I connected to web site with my desktop computers browser, Header contains Sec-WebSocket-Key index in header. But when I connected to web site from an android device, Header contains Sec-WebSocket-Key1 and Sec-WebSocket-Key2, but no Sec-WebSocket-Key. Therefore, It throws an exception. Is there any solution for this problem? Do I need two websokcet implementations, one for mobile and one for desktop?

Thanks in advance.

PepeDeLew
  • 346
  • 4
  • 15
  • Check the android code where it sends the request. If you should only have a single key (Sec-WebSocket-Key), then check why it's sending multiple duplicates. Otherwise, change the PHP code to accept Sec-WebSocket-Key1 or/and Sec-WebSocket-Key2. – Mohammad Tomaraei Dec 14 '13 at 11:25
  • @MohammadReza There is no android code, both reaches to same website. But from desktop It sends one Sec-WebSocket-Key, from android device It sends two, Sec-WebSocket-Key1 and Sec-WebSocket-Key2. – PepeDeLew Dec 14 '13 at 11:33

1 Answers1

0

Sec-WebSocket-Key1 and Sec-WebSocket-Key2 are from early experimental drafts of the websocket proposal.

https://datatracker.ietf.org/doc/html/draft-hixie-thewebsocketprotocol-76#section-8.4

That means your android device (be it the browser or some websocket library) doesn't support the final RFC6455 WebSocket Standard.

To know what version your android device is using ...

  • Look for Sec-WebSocket-Version header, if found, that's your version.
    • Version 13 is RFC-6455 (the finalized spec)
  • Look for Sec-WebSocket-Draft header, if found, that's your draft (non-final) version.
  • Neither of these two, you have a super early draft, possibly hixie-75 or hixie-76 (as those were the first commonly implemented websocket specs)

Version numbers are registered at the IANA WebSocket Version Number Registry. https://www.iana.org/assignments/websocket/websocket.xml

Community
  • 1
  • 1
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Thanks for answer. So I need to check for the version, and implement one for newer versions and one for draft versions. Am I right? – PepeDeLew Dec 14 '13 at 15:04
  • Ignore the draft versions entirely. Seriously, they are not worth the effort. There are very few browsers that use them. Upgrade your browser or websocket client library and you'll be at the final RFC-6455 spec. (aka `Sec-WebSocket-Version: 13`) – Joakim Erdfelt Dec 14 '13 at 16:45
  • For more information see http://stackoverflow.com/questions/1253683/what-browsers-support-html5-websocket-api/2700609#2700609 and http://caniuse.com/websockets – Joakim Erdfelt Dec 14 '13 at 16:46