Firefox 无法建立到 ws://localhost:8000/ 服务器的连接

L3ve 发布于 2013/07/25 16:23
阅读 10K+
收藏 0

用nodejs与websocket简单的结合而已 用node-websocket-server

var websocketGame = {};
$(function () {
    "use strict";
    if (window.WebSocket) {
        //这一句说firefox无法建立连接
        websocketGame.socket = new WebSocket("ws://localhost:8000");

        websocketGame.socket.onopen = function (e) {

            console.log('WebSocket connection established.');
        };

        websocketGame.socket.onmessage = function (e) {
            console.log(e.date);
        };

        websocketGame.socket.onclose = function (e) {
            console.log('WebSocket connection closed.');
        };
    }
});
//server.js  在终端监听用
var ws = require(__dirname + '/lib/ws/server');
var server = ws.createServer();

server.addListener("connection", function (conn) {
    "use strict";
    console.log("A connection established with id", conn.id);
    var message = "Welcome " + conn.id + " joining the party.Total connection:" + server.manager.length;
    server.broadcast(message);
});

server.listen(8000);

console.log("Welcome server is running.");
console.log("Listening to port 8000.");
加载中
0
wi_wi
wi_wi
LZ这问题解决没有,已遇到同样问题?
zheng08
zheng08
你这个问题解决了吗?我也碰到了
廖嘉炜
廖嘉炜
如果你的firefox4的话由于websocket不安全默认不开启,你输入about:config搜websocket手动开启就好了
0
suyuwen1
suyuwen1
nodejs+socket.io用nginx反向代理提示400 Bad Request及ws://…无法连接如何解决
http://www.ihref.com/read-17237.html
0
prefert
prefert
//兼容 FireFox
if ("WebSocket" in window) {
    ws = new WebSocket(url);
} else if ("MozWebSocket" in window) {
    ws = new MozWebSocket(url);
}
返回顶部
顶部