Reputation: 2995
I have two apache virtual hosts for two different applications:
<VirtualHost *:80>
Servername socket1.app
DocumentRoot d:\xampp\htdocs\socket1.app
<Directory d:\xampp\htdocs\socket1.app>
Allow from all
AllowOverride All
Order allow,deny
</Directory>
</VirtualHost>
<VirtualHost *:80>
Servername socket2.app
DocumentRoot d:\xampp\htdocs\socket2.app
<Directory d:\xampp\htdocs\socket2.app>
Allow from all
AllowOverride All
Order allow,deny
</Directory>
</VirtualHost>
When I open http://socket1.app it send connect request to ws://socket1.app:8080 and http://socket2.app send to ws://socket2.app:8080.
A have php server services for both applications based on ratchet php. But applications connect to the same php server(which has been started first).
How I can divide this sockets connections to each app php server service?
Upvotes: 0
Views: 762
Reputation: 3826
You can't have two websocket server instances running on the same port.
You have to either run them on different ports (e.g. 8080 and 8081), or divide the app logic based on the host name.
In RatchetPHP you can do it like this:
public function onMessage(ConnectionInterface $conn, $msg)
{
// The host name that the client connected to (socket1.app or socket2.app)
$host = $conn->WebSocket->request->getHost();
// ... some logic depending on the host name
// if ($host == 'socket1.app')
// {
// ...
// }
}
The first approach is preferable if your websocket apps have totally different logic.
Upvotes: 1