Ratchet
Ratchet copied to clipboard
Option is needed to specify the flash port, or multiple instances can not be launched
This doesn't affect users who are only running one instance of Ratchet at a time, but it seems like Ratchet is hardcoded to only allow one instance on an entire server which seems rather like a bug.
I've been using Ratchet to handle chat on one of my sites for a few years now, and that's worked well.
I'm now trying to add a second application that uses websockets, and in doing so, ran into this error:
It seems 8843 is hardcoded into the source code here: https://github.com/ratchetphp/Ratchet/blob/3b6125c59c6b590b1d81873dd00ac186874deae5/src/Ratchet/App.php#L90
if (80 == $port) {
$flashUri = '0.0.0.0:843';
} else {
$flashUri = 8843;
}
$flashSock = new Reactor($flashUri, $loop);
It isn't clear why this is done, but there's no way to change or override these. That is a severe limitation.
Fortunately, solution to this bug is easy: make the Ratchet constructor take another argument to optionally override that port. That way, I can put my application in separate Ratchet PHP script, as opposed to trying to cram two unrelated things into the same one. (Even if there's a valid reason for discouraging this type of thing, port numbers should always have an override option.)
I went ahead and made this modification to my local copy, and just adding that option and then overriding it as needed fixes the issue.
If you don't use the flash client, you can extend WsServer and remove flash policy support from there completely, that worked for me.
I guess that's another way, and yeah, probably would work since I don't think I'm using it... At the same time, a built-in option like the one I added might be good, esp. for those who do use that feature. I found myself using the custom loop interface param as well when I needed to add my own event loop.
CHANGELOG.md