[SOLVED] [Proxmox API]: vncwebsocket endpoint not sending data (Ratchet)

Kinder

New Member
Apr 18, 2023
4
1
3
Hello,

I'm trying to make a Proxmox interface website for a school project, I have to give access to VMs and visualize them, handle permissions from my own interface... Here are the constraints :
  • I've to use PHP 8 and Symfony 6 for the server side.
  • The client should never have access to the Proxmox API. My Symfony server makes a bridge between the client and the Proxmox API by using the Proxmox root user.

Everything works fine except for the vm visualizer. As you know, I've to use wesockets to read VNC data and then transfer it to my client, so I basically have two websockets on a Ratchet server :
  • The first one to transmit data to the client and read his messages to transfer it to the second websocket.
  • The second to read the vm data and transfer it to the client via the first websocket.

The point where I'm stuck is when I read data from the VM via the vncwebsocket endpoint. You can see here a part of my PHP code :

PHP:
// Connect the client
$reactConnector = new \React\Socket\Connector([
    "tls" => [
        'allow_self_signed' => true,
        'verify_peer' => false,
        'verify_peer_name' => false,
    ]
]);
$connector = new \Ratchet\Client\Connector(connector: $reactConnector);
$connector($fullUrl, [], $headers)->then(
    function (ConnectionInterface $conn) {
        echo "Success handler called";
        $conn->on('message', function($msg) use ($conn) {
            echo "Received: {$msg}\n";
        });
    },
    function () {
        echo "Error handler called";
    }
);

Here $fullUrl is for example :

wss://10.130.166.128:8006/api2/json/nodes/pocmox/qemu/207/vncwebsocket?port=5900&vncticket=PVEVNC%3A643EBCDA%3A%3AJQVHWtcpU%2FKk1ysolJ%2FM7satv4NkRceXDAIZEbw8vZwHsh8679nGAw%2BWaDYhk1E3zTF%2B9zmpwZG5EnPaq4zHaA068KpYmz17PIyEXZnNMLKQO8jo%2FGFPqMGVcTerf3vNWpqJX4rQj6mhzXjkNSQoS1sZSs35yZrGhw4oO2sgMlcPhkBb72l1MSUbv81%2FKAmictRTZuruIRZKJQHeQVcRHekDehNncwJL4GocHhVr1KJcGQen34XjJQAVX2lTXxpFPgjLTfQoNTvwbOhjn8%2BkZJFFN3bTNcLM6cYpUCRkrLpGzPwxZV5RlNdMzIvrHwzTKSs1%2FoH6LFfGW%2Fru7eUXjA%3D%3D

Everything seems to work fine on the Proxmox side, as you can see on Proxmox logs :

Code:
::ffff:10.130.166.128 - - [18/04/2023:17:52:58 +0200] "POST /api2/json/access/ticket?username=root@pam&password=<root password> HTTP/1.1" 200 704
::ffff:10.130.166.128 - root@pam [18/04/2023:17:52:58 +0200] "POST /api2/json/nodes/pocmox/qemu/207/vncproxy?generate-password=0&websocket=1 HTTP/1.1" 200 1976
::ffff:10.130.166.128 - root@pam [18/04/2023:17:52:59 +0200] "GET /api2/json/nodes/pocmox/qemu/207/vncwebsocket?port=5900&vncticket=PVEVNC%3A643EBCDA%3A%3AJQVHWtcpU%2FKk1ysolJ%2FM7satv4NkRceXDAIZEbw8vZwHsh8679nGAw%2BWaDYhk1E3zTF%2B9zmpwZG5EnPaq4zHaA068KpYmz17PIyEXZnNMLKQO8jo%2FGFPqMGVcTerf3vNWpqJX4rQj6mhzXjkNSQoS1sZSs35yZrGhw4oO2sgMlcPhkBb72l1MSUbv81%2FKAmictRTZuruIRZKJQHeQVcRHekDehNncwJL4GocHhVr1KJcGQen34XjJQAVX2lTXxpFPgjLTfQoNTvwbOhjn8%2BkZJFFN3bTNcLM6cYpUCRkrLpGzPwxZV5RlNdMzIvrHwzTKSs1%2FoH6LFfGW%2Fru7eUXjA%3D%3D HTTP/1.1" 101 -

But on the Ratchet server, nothing seems to be displayed, neither in the success or the error callback. After hours of research I couldn't find anything about this specific problem, so I'm sorry if someone already posted a similar issue.

Thanks in advance for your answer !
 
it seems you mage a 'GET' api call (at least that's what the log says), but you must use it as a websocket instead
 
I don't think that's the issue, because as I said, I use a URL begining with wss://, and when I try to use the Proxmox UI VNC console, the log also say that's a GET request.
 
Ok I've some news that might be useful, it seems that Proxmox start the visualizer as I can see on the Proxmox UI tasks (see images below).

proxmox_vnc_1.png
proxmox_vnc_2.png

Given the task duration, we can say that the proxy is not timed out. I don't get why I don't receive any data, did I missed something like sending a packet first ?
 
Ok I got it, the error was from my code, I used ConnectionInterface instead of WebSocket inside the promise resolve function. So the code now looks like this :

PHP:
// Connect the client
$reactConnector = new \React\Socket\Connector([
    "tls" => [
        'allow_self_signed' => true,
        'verify_peer' => false,
        'verify_peer_name' => false,
    ]
]);
$connector = new \Ratchet\Client\Connector(connector: $reactConnector);
$connector($fullUrl, [], $headers)->then(
    function (\Ratchet\Client\WebSocket $conn) {
        echo "Success handler called";
        $conn->on('message', function($msg) use ($conn) {
            echo "Received: {$msg}\n";
        });
    },
    function () {
        echo "Error handler called";
    }
);

I still don't get why nothing was displayed (not even a PHP error), but now it works I've the following result :

Received: RFB 003.008

Thanks for your time !
 
  • Like
Reactions: dcsapak

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!