我正在开发一款多人游戏,并决定使用 NodeJS 作为系统的一部分。 NodeJS 通过 TCP 连接到 m c# 游戏模拟器。
但是我如何向特定用户 ID 发送消息? 数据库中的每个单独用户都有一个唯一的用户 ID (E.G 1)
如果游戏中的用户做了某件事并发送了一条消息,我该怎么做 仅从 Node 到他们。
因为我无法在与 cms 相同的端口(端口 80)上运行 Node 。 我需要一种可以使用 PHP 提取 ID 或其他内容的方法。
用作 Jquery 和“GET”?我很烂。
我所说的消息是指发送 JavaScript 窗口等数据。
可用选项: jQuery JavaScript PHP Node
我想到了一种方法,即通过 PHP 中的参数(例如 $ID)将用户 ID 显示在 div 中,然后使用 JavaScript 检查 div 和消息以查看 ID 是否匹配。然后在消息中将包含用户 ID,然后我可以以某种方式拆分消息吗?所以它是“”,“”(ID,MESSAGE)
代码:
var socket = io.connect(' http://dev.com '); socket.on('字段', 函数(数据) {
if ($("#userid").text().indexOf(data) > -1)
{
window.alert('lol');
console.log(data);
$("#field").html(data);
}
else
{
window.alert("Something has gone wrong with the node server...");
}
});
没有成功。
页面: C#: Node :
最佳答案
根据您在评论中的回复:
Inside the messages are just html that node sends to the page via a Node HTTP server. The messages aren't big just little things like "window.open("google.com");. Messages are only triggered if a user clicks a certain thing within game and no.
在我看来,您真正想要的是某种 RPC。有一个坚实的NPM module called Socket.IO这对你来说很好地概括了这一切。触发一个事件,它可以在服务器端处理,并且任何回调数据都会发送回客户端。
关于c# - 我如何只允许设置某些消息的用户 [NODE.JS],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25903551/