Search code examples
meteorwebsocketddp

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


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.


Solution

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