将数据从服务器发送到不带集合的客户端(使用Websocket) [英] Send data from Server to Client without Collections (with Websocket)

查看:176
本文介绍了将数据从服务器发送到不带集合的客户端(使用Websocket)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Meteor中的WebApp.有一个服务器,一个Web客户端(浏览器)和另一个为C应用程序的客户端. 我已经使用Websocket在C应用程序和服务器之间建立了连接.一切正常,我建立了连接,可以从服务器获取数据,并可以从客户端调用RPC(远程过程调用).

I'm currently working on a WebApp in Meteor. There is a Server, a Web Client (a browser) and another client which is a C application. I've made a connection between my C app and the Server using Websocket. Everything work fine I got connected and I can get data from the Server and call RPC (Remote Procedure Call) from the client.

我实际上需要从服务器到C应用程序调用一些RPC.我知道我可以使用Collections来与我的C应用程序对话,但这不是很合适...

I actually need to call some RPC from the Server to the C app. I know I can use Collections in order to dialog with my C app but it's not very suitable...

我想知道是否有一种方法可以使用当前的Websocket连接将自己的消息发送给C客户端.

I wonder if there is a way to use the current Websocket connection in order to send my own messages to the C client.

推荐答案

我同意您的发现,DDP RPC是客户端在服务器上调用任意方法的一种方法,但是从服务器到客户端都没有RPC功能.

I agree with your findings, DDP RPC is a way for the client to call arbitrary methods on a server, but there's no RPC facility from the server to the client.

不过,Meteor出版物应该可以满足您的需求.您可以使用低级added/changed/removed界面无论出于何种原因,都可以随时向订阅的客户端发送任意数据.您可能只需要实现,例如added.假设您这样做.

A Meteor publication should do what you want, though. You can use the low-level added/changed/removed interface to send arbitrary data to subscribed clients whenever for whatever reason. You probably only have to implement, say added. Let's assume you do this.

客户端可以使用这些数据做任何想做的事情.它只需要调用sub,然后它将开始接收您的added消息.

The client can do whatever it wants with these data. It just needs to call sub, then it will start receiving your added messages.

此代码可能是一个不错的起点.同样,如果只发送并查找added,则只需在服务器和客户端上实现这一位.

This code might be a decent starting point. Again, if you only ever send and look for added, you only need to implement that one bit on the server and client.

这篇关于将数据从服务器发送到不带集合的客户端(使用Websocket)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆