Socket.io : "Cannot read property 'emit' of undefined"
<p>So I'm currently developping my website using socket.io.</p>

<p>Today, while I was implementing the sockets, I got a nice little error <strong>"Cannot read property 'emit' of undefined"</strong>
I can not find what's wrong in my code so I hope you guys can help me.</p>

<p><strong>App.js:</strong></p>

<pre><code>var socket  = require( 'socket.io' );
var express = require('express');
var app     = express();
var server  = require('http').createServer(app);
var io      = socket.listen( server );
var port    = 9999;

server.listen(port, function () {
  console.log('Listening at port %d', port);
});

io.sockets.on('connection', function (socket) {
    console.log('User connected');

    socket.on('create_socket', function(port){
    console.log(port);
});
</code></pre>

<p><strong>Client Side:</strong></p>

<pre><code>&lt;div&gt;
    &lt;p class="connected" hidden&gt;Connected port : 9999&lt;/p&gt;
    &lt;p class="connect_error" hidden&gt;&lt;strong&gt;Can not connect to socket on port 9999&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;script&gt;
    var socket = io.connect("http://localhost:9999");

    // If connection can not be established
    socket.on('connect_error', function(socket) {
        $('.connected').hide();
        $('.connect_error').show();
    });

    // Connection established
    socket.on('connect', function(socket) {
        $('.connect_error').hide();
        $('.connected').show();
       // socket.on('create_socket', null, &lt;?= $port; ?&gt; );
       socket.emit('create_socket', '&lt;?= $port; ?&gt;');
    });
&lt;/script&gt;
</code></pre>

<p>Btw, all the socket.io/jquery/... includes are done correctly even if they doesn't appear on the code</p>

<p>Thanks in advance</p>