Rectangle 27 1

Alright guys, I figured out what was causing it was MAMP PRO server names. Instead of using localhost:8888/mysite I had my local host set up to just use mysite.com (much easier for development purposes as I'm sure you all know) and for some reason this is causing an issue with Firefox and socket.io.

So if anyone is experiencing a similar problem and are using MAMP with a dedicating server name, try using the direct local host path instead and see if it works.

javascript - Node.js/Socket.io working in everything except Firefox, c...

javascript node.js firefox websocket socket.io
Rectangle 27 0

I finally got websockets with socket.io working. The following shows how.

var pageWorkers = require("sdk/page-worker");
var self = require("sdk/self");

pageWorkers.Page({
  contentScriptFile: self.data.url("worker.js"),
  contentURL: self.data.url("worker.html"),
  contentScriptFileWhen: "ready",
  onMessage: function(message) {
    console.log(message);
  }
});

and the worker.html file:

<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="http://domain:port/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect("http://domain:port");
  socket.on('connect', function(){
    socket.on('event', function(data){});
    socket.on('error', function(data){console.log("error: " + error)});
    socket.on('disconnect', function(){});
  });
</script>
</head>
<body>
</body>
</html>

node.js - Socket.io in Firefox add-on - Stack Overflow

node.js sockets websocket firefox-addon socket.io
Rectangle 27 0

Websockets (Socket.IO) is not depend upon CORS. The one of main reason behind Socket.IO is to completely stop CORS kind of issues while dealing with different domains.If you think this can be done by enabling cors, then try this assuming you are using express.js or hapi.js, see this links below to how to enable cors.

new Hapi.Server({
  connections: {
    routes: {
      cors: true
    }
  }
})
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

javascript - CORS error when running node.js and socket.io in firefox ...

javascript node.js sockets firefox
Rectangle 27 0

You can use following code for solve your problem

io.configure(function () { 
   io.set("transports", ["xhr-polling"]); 
   io.set("polling duration", 10); 
});

Does this mean it will only use xhr-pooling and not Websocket at all or when it is possible to use Websocket it will?

node.js - Socket.IO not working in Chrome and Firefox on Windows - Sta...

node.js google-chrome firefox websocket socket.io
Rectangle 27 0

Alright guys, I figured out what was causing it was MAMP PRO server names. Instead of using localhost:8888/mysite I had my local host set up to just use mysite.com (much easier for development purposes as I'm sure you all know) and for some reason this is causing an issue with Firefox and socket.io.

So if anyone is experiencing a similar problem and are using MAMP with a dedicating server name, try using the direct local host path instead and see if it works.

javascript - Node.js/Socket.io working in everything except Firefox, c...

javascript node.js firefox websocket socket.io
Rectangle 27 0

Websockets (Socket.IO) is not depend upon CORS. The one of main reason behind Socket.IO is to completely stop CORS kind of issues while dealing with different domains.If you think this can be done by enabling cors, then try this assuming you are using express.js or hapi.js, see this links below to how to enable cors.

new Hapi.Server({
  connections: {
    routes: {
      cors: true
    }
  }
})
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

javascript - CORS error when running node.js and socket.io in firefox ...

javascript node.js sockets firefox
Rectangle 27 0

I encountered the same issues when trying to publish to AppFog. It's caused by websockets not being supported by AppFog yet, so your fix worked by forcing socket.io to use long polling/AJAX. AppFog is working on supporting websockets according to their website, but no dates have been given.

Most cloud PaaS providers that I have found do NOT support websockets yet unfortunately. One notable exception that I am testing out now is Nodejitsu: http://nodejitsu.com/

node.js - Socket.io does not work on Firefox & Chrome - Stack Overflow

node.js socket.io
Rectangle 27 0

I believe you're using the wrong socket.io.js file for the client?

you should use these files in a folder where you have your client-side stuff on, ie: ../js/socket.io.min.js

About the require problem, are you using npm? go into the nodeJS project folder and run the following:

npm install socket.io

this should install to the node_modules folder inside your project folder and by doing a require('socket.io'); you should be able to access the module.

if this isn't working, you probably have a corrupt installation of node.

PS: Are you using the same port for the files? you seem to be looking for the socket.io file on port 8080 and then connecting to nodeJS on port 8080 for socket connections...

Even I'm having the same problem. It does not work on Firefox and Chrome but it works just fine on IE. Please help.

node.js - Socket.io fails to emit messages to Node server on Chrome & ...

firefox node.js google-chrome websocket socket.io
Rectangle 27 0

I just found out that it was due to the anti virus of the person who was having issues in Chrome and Firefox. Apparently it blocks websockets and even polling on those browsers. I also change the port from 8080 to 8079.

node.js - Socket.IO not working in Chrome and Firefox on Windows - Sta...

node.js google-chrome firefox websocket socket.io
Rectangle 27 0

Websockets (Socket.IO) is not depend upon CORS. The one of main reason behind Socket.IO is to completely stop CORS kind of issues while dealing with different domains.If you think this can be done by enabling cors, then try this assuming you are using express.js or hapi.js, see this links below to how to enable cors.

new Hapi.Server({
  connections: {
    routes: {
      cors: true
    }
  }
})
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

javascript - CORS error when running node.js and socket.io in firefox ...

javascript node.js sockets firefox
Rectangle 27 0

I believe you're using the wrong socket.io.js file for the client?

you should use these files in a folder where you have your client-side stuff on, ie: ../js/socket.io.min.js

About the require problem, are you using npm? go into the nodeJS project folder and run the following:

npm install socket.io

this should install to the node_modules folder inside your project folder and by doing a require('socket.io'); you should be able to access the module.

if this isn't working, you probably have a corrupt installation of node.

PS: Are you using the same port for the files? you seem to be looking for the socket.io file on port 8080 and then connecting to nodeJS on port 8080 for socket connections...

Even I'm having the same problem. It does not work on Firefox and Chrome but it works just fine on IE. Please help.

node.js - Socket.io fails to emit messages to Node server on Chrome & ...

firefox node.js google-chrome websocket socket.io
Rectangle 27 0

That is a bug around Web Socket and some modern browsers.Even this test will not work. Read the following issues.

node.js - Socket.io doesn't work on Chrome and Firefox - Stack Overflo...

node.js socket.io
Rectangle 27 0

Thankyou ebohlman for your time but I solved the problem. In my chat.js I added the following line.

io.configure('development', function(){
  io.set('transports', ['xhr-polling']);
});
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs');

app.listen(8124);

io.configure('development', function(){
  io.set('transports', ['xhr-polling']);
});

function handler (req, res) {
fs.readFile(__dirname + '/chat.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading chat.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
    socket.on('addme',function(username) {
        socket.username = username;
        socket.emit('chat', 'SERVER', 'You have connected');
        socket.broadcast.emit('chat', 'SERVER', username + ' is on deck');
    });
    socket.on('sendchat', function(data) {
        io.sockets.emit('chat', socket.username, data);
    });
    socket.on('disconnect', function() {
        io.sockets.emit('chat', 'SERVER', socket.username + ' has left the building');
    });
});

But I still don't know what might have caused the error. If you know please explain!

+1 because that line at least made it working in Google Chrome for me. I was just banging my head since an hour to make that work. Thanks for posting this :)

For some reason it doesn't work in IE and Mozilla, in case anybody has any solutions please post, Thanks..

Thanks for posting this answer.. it was a headache for me too. :)

node.js - Socket.io does not work on Firefox & Chrome - Stack Overflow

node.js socket.io
Rectangle 27 0

I think this will help to know about the issue, and how it fixes I searched lot for it and finally I got it

node.js - Socket.io does not work on Firefox & Chrome - Stack Overflow

node.js socket.io