Can Ratchet WebSocket Server send a message to client itself?

19,643

Solution 1

That is indeed possible. You need to communicate with the WebSocket server process somehow. You can do that by using some form of message passing, be it RPC or a message queue.

Ratchet itself is based on the React event loop. This means that any form of communication with Ratchet must be integrated with that event loop. On the React homepage you can see some of the integrations that already exist:

In the Ratchet documentation there is a tutorial on how to use React/ZMQ in order to push messages from anywhere to your WebSocket server.

Solution 2

Ratchet also implements WAMP, which includes PubSub. So your clients can subscribe to some topics, and you can have other clients (running i.e. on your backend infrastructure) publish to those topics. You could i.e. have an AutobahnPython based client publishing via Ratchet to an AutobahnAndroid based mobile app or AutobahnJS based HTML5 client.

Share:
19,643
lexa
Author by

lexa

Updated on June 11, 2022

Comments

  • lexa
    lexa almost 2 years

    I want to use a Ratchet (http://socketo.me) for permanent connection between iPhone Apps and Server. And I need to exchange data between apps and server.

    From this example (http://socketo.me/docs/hello-world) I've found out that I have a function onMessage that will be called when the App send a massage to the server and the server could send a response to the App.

    But the server also must have an ability to send data to the app without getting data from app. For example, the connection between app and server has been established. Something happened on the server and we need to send a new data to the app. How can I do it and is it possible?

    The main question is how can I send data to the App from the server?

    Thank you for any help.

  • lexa
    lexa over 11 years
    Good example for React/ZMQ. But I can not find out how I can push proper data (for example, a special json I've created) to proper user. For example, I have to send data to the proper users (I have lists of user's id). Is this necessary that user has already been subscribed to 'specific page' (like they say here: socketo.me/docs/push)?
  • lexa
    lexa over 11 years
    igorw, cloud we to be connected somehow (skype, for exmaple) to ask a question direct to you. And thank you for your help.
  • igorw
    igorw over 11 years
    There is a #reactphp IRC channel on irc.freenode.net.
  • harveyslash
    harveyslash almost 8 years
    it uses wampv1 , and iOS doesn't have a library for v1. Is there a way to do push using MessageComponent Interface ?
  • oberstet
    oberstet almost 8 years
    Thruway supports WAMPv2 github.com/voryx/Thruway, so you shoud be able to use github.com/mogui/MDWamp with it
  • indianwebdevil
    indianwebdevil about 7 years
    Works great! but this works sort of like ack, once the server gets a message you send a message to the client. How do i send (initiate) a message to the client without getting a message from the client