node.js with socket.io error on IIS 7.5 with iisnode installed

I am new to node.js and socket.io.

I installed node.js and iisnode on a Window Server 2008 R2 running IIS 7.5, also installed "URL rewrite" and "Web Deploy" as suggested by "tjanczuk".

Examples that come with iisnode run just fine.

But I am having some problems when adding socket.io to a project. I started by modifying an example that I found.

The url is http://localhost/node/streamData/

Here is the server code:

var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);

io.configure(function(){
    io.set('resource', 'streamData/server.js'); //Where we'll listen for connections.
});

var fs = require('fs');
var mysql = require('mysql');
var connectionsArray = [];
var connection = mysql.createConnection({
  host     : 'host',
  user     : 'user',
  password : 'password',
  database : 'db' 
    });
var POLLING_INTERVAL = 3000;
var pollingTimer;

// If there is an error connecting to the database
connection.connect(function(err) {
  // connected! (unless `err` is set)
  console.log(err);
});

// creating the server 
app.listen(process.env.PORT||8081);

// on server started we can load our client.html page
function handler(req, res) {
  fs.readFile(__dirname + '/client.html', function(err, data) {
    if (err) {
      console.log(err);
      res.writeHead(500);
      return res.end('Error loading client.html');
    }
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end(data);
  });
}

And here my client:

    <html>
        <head>
            <title>Push notification server streaming on a MySQL db</title>
            <style>
                dd,dt {
                    float:left;
                    margin:0;
                    padding:5px;
                    clear:both;
                    display:block;
                    width:100%;
                }
                dt {
                    background:#ddd;
                }
                time {
                    color:gray;
                }
            </style>
        </head>
        <body>
            <time></time>
            <div id="container">Loading ...</div>
        <!--<script src="node_modules/socket.io/node_modules/socket.io-client/socket.io.js"></script>-->
        <script src="socket.io/socket.io.js"></script>
        <script src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script>

            // create a new websocket
            var socket = io.connect('http://localhost',{recource: 'streamData/server.js'});
            // on message received we print all the data inside the #container div
            socket.on('notification', function (data) {
               // show data...
            });

          });
        </script>
        </body>
    </html>

I get the following error:

<p>iisnode encountered an error when processing the request.</p><pre style="background-color: eeeeee">HRESULT: 0x2
    HTTP status: 500
    HTTP subStatus: 1002
    HTTP reason: Internal Server Error</pre><p>You are receiving this HTTP 200 response because <a href=https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config>system.webServer/iisnode/@devErrorsEnabled</a> configuration setting is 'true'.</p><p>In addition to the log of stdout and stderr of the node.exe process, consider using <a href=http://tomasz.janczuk.org/2011/11/debug-nodejs-applications-on-windows.html>debugging</a> and <a href=http://tomasz.janczuk.org/2011/09/using-event-tracing-for-windows-to.html>ETW traces</a> to further diagnose the problem.</p><p>The last 64k of the output generated by the node.exe process to stderr is shown below:</p><pre style="background-color: eeeeee">Application has thrown an uncaught exception and is terminated:
    TypeError: Object #&lt;Server&gt; has no method &apos;configure&apos;
    at Object.&lt;anonymous&gt; (C:\Program Files\iisnode\www\streamData\server.js:5:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.&lt;anonymous&gt; (C:\Program Files\iisnode\interceptor.js:210:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

Playing with the code I am able to pass one error, but run into another. The code bellow give me Object #Server has no method configure

    var io = require('socket.io').listen(app);

    io.configure(function(){
        io.set('resource', 'streamData/server.js'); //Where we'll listen for connections.
    });

Any guidance is appreciated.

Best Regards.

I think you are not loading socket.io correctly. Your code worked correctly on localhost, right? I had a similar problem as you, take a look at it: EC2 with socket.io. In short you need to supply the full url for the socket.io to which he needs to connect to, otherwise with your code

io.connect('http://localhost',{recource: 'streamData/server.js'})

will try to connect to localhost.

Thanks,

Got it to work!.

Here are the changes made.

On the client:

    <script src='//localhost:8081/socket.io/socket.io.js'></script>
    var _addr = window.location.protocol + '//' + window.location.host + ':8081';
    var socket = io.connect(_addr);

But first need to run > "node server.js" if not, I get syntax error message(:-)).