1

For a new project I need to implement remote desktop protocols. The addresses of the remote need to be secured and may never get sent to the client. After a lot of research and some tests I found Guacamole, which also has a Java client. The project is designed as an API though, so I started porting some bits of the Java client example to PHP.

The use case will be the following:

  • User logs into my service (Laravel application)
  • WebSocket connection establishes to a constantly running PHP script (using HOA\WebSocket)
  • Upon authorization a TCP socket needs to be established to the Guacamole Daemon
  • Commands coming via WebSocket need to be directed to the Guacamole Daemon and vice versa

What makes this complicated is the fact that the application needs to be able to serve multiple clients simultaneously. Multiple TCP sockets need to be established and multiple WebSocket connections need to be managed all at once.

For my simple test I opened the socket via fsockopen and then looped to wait for data. With this I obviously can't listen to multiple sockets at once (at least realistically), but I stumbled upon the React Socket Client library:

Think of this library as an async version of fsockopen() or stream_socket_client().

This sounds like it is what I need, but then again, I'm using HOA and its WeSocket server, which apparently also runs in a loop (when invoking WebsocketConnectionHandler->run()).

Should I even be using React's Socket Client or should I try to use HOA's Socket library instead (seeing as I'm already using WebSocket from that)? Are React and HOA even compatible in their event loop, so could I listen to WebSocket clients and a TCP connection at the same time?

If so, could anyone give me some hints or examples on how to get started with coupling these two? Thanks!

padarom
  • 3,529
  • 5
  • 33
  • 57

0 Answers0