Web套接字在Firefox 12中不起作用 [英] Web socket not working in Firefox 12

查看:91
本文介绍了Web套接字在Firefox 12中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firefox无法在ws://192.168.0.155:5555/socket/server3.php建立与服务器的连接.

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错误了我的代码

wts wrong with my code ??

推荐答案

从您的一条评论中,我认为您正在使用 phpwebsocket 在服务器上.该项目似乎没有得到维护,也没有及时更新websocket协议规范.

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.

正在使用两个不兼容的Websocket协议版本. Safari仍然使用phpwebsocket实现的原始(现已弃用) Hixie 变体; Firefox,IE10和Chrome使用更新的 Hybi 变体.

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.

要对此进行测试,您可以尝试使用Safari执行JavaScript.

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

我不确定如果要在服务器上使用PHP并且需要支持的功能超过Safari,可以使用哪些选项.我可以看到一个开源服务器,它应该支持上面列出的所有浏览器.另外,如果您想尝试编写自己的服务器,可以在此从websocket标签下发布很多问题,以汲取灵感.

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.

这篇关于Web套接字在Firefox 12中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆