从VB.NET与node.js通信



我有一个node.js-app在同一台机器上的8080端口上运行,具有不同的通道。我的jquery站点和。net端点之间的通信工作得很好。

我的网站:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
            <title>WebSocket-Test</title>
    </head>
    <body>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript" src="/socket.io/socket.io.js"></script>
        <script type="text/javascript">
            $(function() {
                $('button').click(function() {
                    var socket = io.connect('http://localhost:4000');
                    socket.on($('#username').val(), function (data) {
                        console.log(data);
                        socket.emit('my other event', { my: data });
                    });
                });
            });
        </script>
        <input type="text" id="username" />
        <button>connect</button>
    </body>
</html>
我node.js-server

:

var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')
app.listen(4000);
var count = 0;
function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }
    res.writeHead(200);
    res.end(data);
  });
}
io.sockets.on('connection', function (socket) {
    setInterval(function () {
        socket.emit('daniel', { hello: 'Waited two seconds!'});
    }, 2000);
    socket.emit('daniel', { hello: 'world' });  
    socket.emit('stefan', { hello: 'world2' });  
    socket.on('my other event', function (data) {
        console.log(data);
    });
});

我的问题是,我如何通过node.js从我的。net后端发送消息?

在我的页面加载后,我确实有一个window.io-object。最好的方法是什么?只是做一个eval上的io对象与发送和通道,或者我可以传递一个对象或json的东西到我的node。js-server?

我的目标是发送事件驱动的消息。

当一个新行插入到我的MSQL-DB中时,应该向通道发送一条消息。

您可以做的一件事是,当有更新的详细信息时,简单地ping Node.js服务器。您可以直接通过http/https完成此操作。

基本上,当。net更新数据库时,它可以向node.js端点发送一个快速POST,其中包含您想要向用户推出的数据包。

最新更新