2

I would like to use websockets with a Jetty-Server (Version 8.1.9) only if the websocket-version is 13 aka RFC 6455 is available. If its not available a http-fallback-solution will be used.

[random Browser Javascript]  <--websocket v13 only--> [Jetty Server Java]

The websocket-protocol-version is stored inside the WebSocket handshake request:

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

Now I'd like to have something like this in javascript:

if (window.WebSocket)
{
    // browser supports websockets
    if (bla.websocketversion != 13)
    {
        // wrong websocket version
        // use fallback connection
    }
    else
    {
        // use websockets
    }
}
else
{
    // use fallback connection
}

If I connect to the Jetty-Server using a iPad with Safari 5.0.2 (which appearently uses an older websocket protocol) I get a Warning: WARN:oejw.WebSocketFactory:Unsupported Websocket version: 2147483647

I could not find a way to get the access or change the handshake request in Javascript. Is it impossible? Any workarounds for this?

1 Answers1

0

It might be a suggestion, as of now we cant able to get any properties form websocket object. So we can test a websocket connection for a particular amount of time. It might be a temporary workaround.

This workaround only when connection doesnt make, websocket readystate still connecting

function init()
{

  _ws = new WebSocket("ws://example.com");

  _ws.onopen = onopen();

  _ws.onclose = onclose();

   setTimeout(function () {connectionCheck(_ws)}, 5000);

}


function connectionCheck(_ws)
{


   if(_ws.readyState == 0)
   {
      //call your fallback sollution
   }
   else
   {
      return;
   }
}
Guru Kara
  • 6,272
  • 3
  • 39
  • 50
raky
  • 181
  • 1
  • 2
  • 11