I'm running ReactPHP in a Docker environment to listen for WebSocket messages. I use the port mapping feature like so:
docker run \
--detach \
-p 10002:8081 \
missive-controller
Thus, the external port 10002 maps to 8081 inside the container.
Inside my implementation of MessageComponentInterface
, I have this event handler:
public function onMessage(ConnectionInterface $from, $msg)
{
echo sprintf(
"Connection %d sent message \"%s\" to WS server\n",
$from->resourceId,
$msg
);
/* @var $request \Guzzle\Http\Message\EntityEnclosingRequest */
$request = $from->WebSocket->request;
// ... do stuff
}
Now, I am listening to a couple of ports in ReactPHP, in order to differentiate between internet WebSocket requests, and private messages from other containers on the private Docker network. So, to detect the port, I do this (using the Guzzle object set up above):
$request->getPort();
However, that gets me 10002 (the internet port) rather than the internal container-side port (8081). I have a mapping device to look up the association for now, but can I obtain the container port directly?
I am running Ratchet 0.36.