【问题标题】:How to publish data in a room from a .NET code?如何从 .NET 代码在房间中发布数据?
【发布时间】:2011-07-27 21:20:04
【问题描述】:

我有一个用 .NET 编写的 web 服务...我需要从这个 web 服务发送一个命令到 socket.io 服务器,这将使服务器在通道上发布数据。我通过发送 HTTP 请求使用 APE 完成了此操作。但是,我无法弄清楚如何在 socket.io 中做到这一点

以前有没有人在 socket.io 中做过类似的事情?

谢谢

【问题讨论】:

  • "服务器" "数据" -- 是的,我知道你说的那个。
  • 哦,来吧。无论如何,server 代表 socket.io,data 是指我想在房间里发布的数据。
  • 在这种情况下,什么是“房间”?
  • 一个房间就像一个聊天室。在彗星的行话中,你可以将房间称为“通道”

标签: node.js httprequest socket.io


【解决方案1】:

我有一个较旧的示例,我通过侦听不同的端口来完成此操作:

var http = require('http'),
io = require('socket.io');


/** standard http requests **
******************************/
server = http.createServer(function(req, res){ 
// your server code 
res.writeHead(200, {'Content-Type': 'text/html'}); 
res.end('<h1>Hello world</h1>');
});
server.listen(80);


/*** server to server connections ***
 ***********************************/
var serverConnections = http.createServer(function (req, res) {
    // ... parse params and broadcast message to the socket.io 
    //  connections attached below...
    // ... 
    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.end('done');
});
serverConnections.listen(8080);

/*** socket.io connections **/
*****************************/
var socket = io.listen(server);
socket.on('connection', function (client) { ... });

【讨论】:

  • 对不起。这不是我要找的。我希望从 .NET 发布数据。第二点,您不必在 2 个端口上创建 2 个服务器来模拟聊天室。在 socket.io 0.7 中,你有房间的概念。查看socket.io的google组
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-23
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多