繁体   English   中英

在安装了iisnode的IIS 7.5上具有socket.io错误的node.js

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

我是node.js和socket.io的新手。

我在运行IIS 7.5的Window Server 2008 R2上安装了node.js和iisnode,并按照“ tjanczuk”的建议安装了“ URL rewrite”和“ Web Deploy”。

iisnode附带的示例运行良好。

但是将socket.io添加到项目时遇到一些问题。 我首先修改了一个发现的示例。

网址是http://localhost/node/streamData/

这是服务器代码:

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);
  });
}

我的客户在这里:

    <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>

我收到以下错误:

<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)

使用代码,我能够传递一个错误,但是遇到另一个错误。 下面的代码给我对象#Server没有配置方法

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

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

任何指导表示赞赏。

最好的祝福。

我认为您没有正确加载socket.io 您的代码可以在localhost正常工作,对吗? 我遇到了与您类似的问题,请看一下: 带socket.io的EC2 简而言之,您需要提供他需要连接到的socket.io的完整URL,否则请提供您的代码

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

将尝试连接到本地主机。

谢谢,

得到它的工作!。

这是所做的更改。

在客户端上:

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

但是首先需要运行>“ node server.js”,否则会收到语法错误消息(:-)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM