Web socket not working in Firefox 12

781 views Asked by At

Firefox can't establish a connection to the server at ws://192.168.0.155:5555/socket/server3.php.

$(document).ready(function(){
if(!("WebSocket" in window)){
alert('not available');
}else{
_init(); 
}
});
function _init(){
     var websocket;
     var host = 'ws://192.168.0.155:5555/socket/server3.php';
     try{
     websocket = new WebSocket(host);
     websocket.onopen = function(evt){ onOpen(evt); };
     websocket.onclose = function(evt) { onClose(evt); };
     websocket.onmessage = function(evt) { onMessage(evt); };
     }catch(exception){
     alert(exception);
     }
     }

  function onOpen(evt){
    $('.logger_screen').append('Connected');
      }

  function onClose(evt){
      $('.logger_screen').append('Disconnected');
       }

  function onMessage(evt){
    $('.logger_screen').append(evt.data);
   }

wts wrong with my code ??

1

There are 1 answers

0
simonc On BEST ANSWER

From one of your comments, I think you're using phpwebsocket on the server. This project doesn't seem to be maintained and hasn't stayed up to date with changes in the websocket protocol spec.

There are two incompatible versions of the websocket protocol in use. Safari still uses the original (now deprecated) Hixie variant which phpwebsocket implements; Firefox, IE10 and Chrome use the newer Hybi variant.

To test this out, you could try using Safari to to execute your javascript.

I'm not sure what options you have if you want to use PHP on the server and need to support more than Safari. I can see one open source server which should support all the browsers listed above. Alternatively, if you want to try writing your own server, there are quite a few questions posted here, under the websocket tag, that you could take inspiration from.