- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我将给出我正在尝试做的事情的一个小前提。我有一个游戏概念,需要多个玩家围坐在一张 table 旁,有点像扑克牌。
不同播放器之间的正常交互,通过socket.io结合node js很容易处理。
我很难弄明白的是;我有一个 cron 作业正在另一个进程中运行,该进程每分钟获取新信息,然后需要将这些信息发送给每个玩家。由于这是一个不同的过程,我不确定我如何向某些客户发送此信息。
socket.io 确实有这方面的信息,我在下面引用它:
In some cases, you might want to emit events to sockets in Socket.IO namespaces / rooms from outside the context of your Socket.IO processes. There’s several ways to tackle this problem, like implementing your own channel to send messages into the process. To facilitate this use case, we created two modules: socket.io-redis socket.io-emitter
据我了解,我需要这两个模块来执行我之前提到的操作。然而,我不明白的是,当我只需要发送一些消息时,为什么要使用 Redis。
是用来临时存储消息的吗?
任何帮助将不胜感激。
最佳答案
如果您只需要在外部事件后发出,有多种方法可以实现这一点。这取决于您使用什么来获取要发送的新数据:
/* if the other process is an http post incoming you can use for example
express and use your io object in a custom middleware : */
//pass the io in the req object
app.use( '/incoming', (req, res, next) => {
req.io = io;
})
//then you can do :
app.post('/incoming', (req, res, next) => {
req.io.emit('incoming', req.body);
res.send('data received from http post request then send in the socket');
})
//if you fetch data every minute, why don't you just emit after your job :
var job = sheduledJob('* */1 * * * *', io => {
axios.get('/myApi/someRessource').then(data => io.emit('newData', data.data));
})
关于node.js - Node JS Socket.IO 发射器(和 redis),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35392048/
我是 Arduino 和这个论坛的新手,这是我除了教程之外的第一个 Arduino 项目。 我正在尝试使用遥控发射器/接收器和 Arudino 来控制伺服。我使用 Arduino 而不是将伺服器直接连
我喜欢听一个特定的广播,我用 vlc 给自己做了一个小发射器,就像这样: #!/bin/sh vlc http://mp3lg.tdf-cdn.com/fip/all/fiphautdebit.mp3
是否有用于发出 YAML 的 C++ 库?维基百科提到了 libyaml 的 c++ 包装器,但链接已断开。 YAML官方网站只提供yaml-cpp ,这也在 this 中提出所以问题,但 cpp-y
我正在尝试将我的 iPhone 设置为广播 iBeacon 信号以供另一部 iPhone 接收。本应接收信号的 iPhone 可以正常工作,但我无法让另一部 iPhone 广播信号。 我正在学习本教程
我正在编写一个网络应用程序,其中多个监听器(Evcentsource SSE 客户端 JS)将连接到我的服务器。我想做的是 为每个连接的监听器存储 SSE 发射器:可以在内存中或通过为每个客户端分配
我想在后端进行串行工作。我想选择 geo_unit 并做另一项工作并向客户端写入响应。 我读了 http://nodejs.org/docs/v0.4.7/api/events.html#events
我从早期就使用 BIRT,但仍然有关于 PDF 发射器的谜语。 短篇小说 : 我可以配置 fontsConfig.xml 以从相对路径或 jar 加载字体吗? 长话: 我们同时使用 FOP 和 BIR
今天我得到了一些很酷的 radio 接收器和发射器,问题是当我输入我想发送的消息时,它会在另一个 arduino 上吐出乱码。 //transmitter #include void setup()
我有一个使用 html canvas 函数创建的形状(四分之一圆): 移动到 LineTo QuadraticCurveTo 如何将形状爆炸成粒子,然后将它们返回形成一个圆圈? 最佳答案 我不会为您编
我正在实现自定义 Birt 发射器,我需要知道单元格、表格或网格的宽度和高度(以像素或点为单位)。如果未在报表设计器中明确设置度量,则会出现此问题。 我试图通过调用 cellContent.getWi
我将给出我正在尝试做的事情的一个小前提。我有一个游戏概念,需要多个玩家围坐在一张 table 旁,有点像扑克牌。 不同播放器之间的正常交互,通过socket.io结合node js很容易处理。 我很难
我是一名优秀的程序员,十分优秀!