varspool / Wrench

A simple PHP WebSocket implementation for PHP 7.1
Do What The F*ck You Want To Public License
596 stars 210 forks source link

Pass data between Applications #89

Closed scgrant327 closed 8 years ago

scgrant327 commented 8 years ago

Let's say I have a websocket servicing two applications, an Upload and a Download.

When the Upload receives data, I want to be able to push that data out to all clients who have connected via the Download application (and have requested to be included in the download).

How can I do that?

Alarmfifa commented 8 years ago

Hi,as far as I understand it coul'd be a bit difficult. Here server initializes onUpdate method for each application. Inside application you can manage your own list of clients and catch events. I think you can modify a Server-class and add some global parameter, but... Could you explain why do you need to use strictly two different applications? I solved a simular issue with one application. I have two types of client: one of them can only listen socket and the other one can send a push notification. In time of connect to wrench server, client specifies his role with GET parameter. Something like /websocket/?act=send or /websocket/?act=listen. And It's very easy to manage these two queues in one application.

scgrant327 commented 8 years ago

Actually, I think I have found a way... First, the reason I am separating the functionality out is to segregate the traffic. I anticipate 1000+ uploaders and 1million+ downloaders... Just trying to put a fence around each group.

So, in my ClientApp, I add a public var which identifies the role as a client, same in my UploadApp but as an uploader. Also in the ClientApp, I add a Distribution public function to send out data to all connected clients, who have signed up for this specific data.

In the Connection class, after passing the Uploaded data off to the handler (which inserts it into a database), I grab a pointer to the ClientApp and pass the incoming data off to the Distribution function.

Seems to work Ok so far for my needs.