title: NodeJS work fine with IE but unstable with Chrome, Firefox and Opera
body: <p>I am working on a chat system using nodejs and socket.io. So far my application work perfectly with Internet Explorer 10 but most of the time i can't send message on Firefox or Chrome or Opera (but i can still read message sent from IE in Chrome/Firefox/Opera). All my browser is updated to newest version, and without any addon/extension. I have also tried several different free port but without any result. I am working on Windows 7 environment and all my test was done locally.</p>
  
  <p>I have no idea what went wrong, been scratching my head for last few hours but can't figure anything. I am new to node.js so please help !</p>
  
  <p>Edit : I tried to force the transport to websocket by using io.set('transports', ['websocket']); and now IE stop working as well, so it seem before the reason IE work is socket.io force IE to use xhr-polling instead of websocket. </p>
  
  <p>My code is as below (taken from <a href="http://code.tutsplus.com/tutorials/real-time-chat-with-nodejs-socketio-and-expressjs--net-31708" rel="nofollow noreferrer">http://code.tutsplus.com/tutorials/real-time-chat-with-nodejs-socketio-and-expressjs--net-31708</a>)</p>
  
  <p><strong>Server index.js</strong></p>
  
  <pre><code>    var express = require("express");
      var app = express();
      var port = 3700;
  
  
      app.set('views', __dirname + '/tpl');
      app.set('view engine', "jade");
      app.engine('jade', require('jade').__express);
      app.get("/", function(req, res){
          res.render("page");
      });
  
      app.use(express.static(__dirname + '/public'));
  
      var io = require('socket.io').listen(app.listen(port));
      console.log(port);
      console.log(io);
  
      io.sockets.on('connection', function (socket) {
  console.log("connect");
          socket.emit('message', { message: 'welcome to the chat !' });
          socket.on('send', function (data) {
              io.sockets.emit('message', data);
          });
      });
  
      console.log("Listening on port " + port);
  </code></pre>
  
  <p><strong>The view</strong></p>
  
  <pre><code>    doctype html
      head
          title= "Real time web chat"
          script(src='/chat.js')
          script(src='/socket.io/socket.io.js')       
          body
              #content(style='width: 500px; height: 300px; margin: 0 0 20px 0; border:         solid 1px #999; overflow-y: scroll;')
  </code></pre>
  
  <p>.controls
              | Name: 
              input#name(style='width:350px;')
              br
              input#field(style='width:350px;')
              input#send(type='button', value='send')</p>
  
  <p><strong>Chat.js</strong></p>
  
  <pre><code>    window.onload = function() {
  
  var messages = [];
  var socket = io.connect('http://localhost:3700');
  var field = document.getElementById("field");
  var sendButton = document.getElementById("send");
  var content = document.getElementById("content");
  var name = document.getElementById("name");
  
  socket.on('message', function (data) {
      if(data.message) {
          messages.push(data);
          var html = '';
          for(var i=0; i&lt;messages.length; i++) {
              html += '&lt;b&gt;' + (messages[i].username ? messages[i].username : 'Server') + ': &lt;/b&gt;';
              html += messages[i].message + '&lt;br /&gt;';
          }
          content.innerHTML = html;
      } else {
          console.log("There is a problem:", data);
      }
  });
  
  sendButton.onclick = function() {
      if(name.value == "") {
          alert("Please type your name!");
      } else {
          var text = field.value;
          socket.emit('send', { message: text, username: name.value });
      }
  };
  </code></pre>
  
  <p>}</p>
  
  <p>Edit : According to the similar question <a href="https://stackoverflow.com/questions/11350279/socket-io-does-not-work-on-firefox-chrome?rq=1">Socket.io does not work on Firefox &amp; Chrome</a> it was fixed by adding below code into chat.js. I did it and it work on chrome/firefox/opera now but it is forcing the browser to use long-pooling/ajax instead of websocket, and i want my browser to use websocket (chrome/firefox should be able to support websocket better than IE i think ?)</p>
  
  <pre><code>    io.configure('development', function(){
        io.set('transports', ['xhr-polling']);
      });
  </code></pre>