Send data from Server to Client without Collections (with Websocket)

六月ゝ 毕业季﹏ 提交于 2019-12-11 13:58:12

问题


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.

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...

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


回答1:


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.

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.

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

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.



来源:https://stackoverflow.com/questions/27692020/send-data-from-server-to-client-without-collections-with-websocket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!