title: How to use Express post request to emit Socket.io or Sockjs?
body: <p>I know this question is kind of awkward, but the problem comes from Samsung TV 2010 / 2011 SmartTV (and blue ray player; of course 2012 emulator working fine). I ported the simple chatting examples come from the source and package to SmartTV app. Both of them fall back to JSONP polling, but from SmartTV app only could emit / push to server once. Receiving the message from server could be multiple times without any problem. After looking for the answer in Samsung D forum (of course nothing there), I think the fastest way to work around this issue is to deploy an Express server, taking the post data and JSON.parse, then emit Socket.io / Sockjs internally inside the server itself.</p>
  
  <p>Could anybody show me an easy sample code so I could start from there? Thanks a lot.</p>
  
  <p>I quickly make code, but seems it doesn't work:</p>
  
  <p>lib/server.js</p>
  
  <pre><code>var express = require('express')
    , app = express.createServer()
    , io = require('socket.io').listen(app);
  
  app.listen(80);
  
  app.use(express.bodyParser());
  
  app.get('/', function (req, res) {
    res.sendfile('/var/www/mpgs_lite_v3/index.html');
  });
  
  app.post('/', function(req, res){
    console.log(req.body);
    io.sockets.emit('my other event', req.body);
    res.redirect('back');
  });
  
  io.sockets.on('connection', function (socket) {
    //socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
      console.log(data);
    });
  });
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    var socket = io.connect('http://localhost');
    socket.on('news', function (data) {
      console.log(data);
      socket.emit('my other event', { my: 'data' });
    });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form method="post" action="/"&gt;
       &lt;input type="hidden" name="_method" value="put" /&gt;
       &lt;input type="text" name="user[name]" /&gt;
       &lt;input type="text" name="user[email]" /&gt;
       &lt;input type="submit" value="Submit" /&gt;
   &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>'my other event' seems not receive anything.</p>