We have built a Ratchet websocket server that serves a standalone client application. The server is running on port 8080, and our Symfony app is running on port 80. It's critical that we have sessions working within the websocket server so we can uniquely identify each client. The problem is that Ratchet does not send a set-cookie header over port 8080.
Hoping to find a way to send the set-cookie header in response to the upgrade request on 8080, I tried to start a new session in onOpen():
use Symfony\Component\HttpFoundation\Session\Session;
class ClientApi implements MessageComponentInterface {
/**
* @inheritDoc
*/
public function onOpen(ConnectionInterface $conn) {
$conn->Session = new Session();
$conn->Session->start();
}
...
But this did not result in a set-cookie header being sent back in the response to the upgrade request.
We have a workaround where the client has to first do a GET on port 80 to get a cookie before sending the websocket upgrade request over 8080, so it can send the cookie with the upgrade request. I'm hoping to get something working like I tried above, so the client does not have to bother the web app on port 80.
Am I missing something?
I believe by default creating a new Symfony Session class will use global variables. Ratchet provides a Session middleware class that will attach a Symfony Session object to each ConnectionInterface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With