Can i point the websocket payload to another memory location ?

noweare
Posts: 101
Joined: Tue Jul 02, 2019 11:35 am

Can i point the websocket payload to another memory location ?

Postby noweare » Tue Aug 19, 2025 11:54 pm

Question about ws_echo_server example in http_server directory

The websocket packet payload is a uint8_t* and memory is allocated to store the request payload.
In the example the response uses in the same address for the payload.

I need to use more memory for the response but if I assign another address which points to the response I want to send
the payload doesn't accept it.

The payload address is the original address assigned to it.

Code: Select all

    
    if ((ws_pkt.type == HTTPD_WS_TYPE_TEXT) && (strstr((char *)ws_pkt.payload, "quick") != 0))
    {      
          ws_pkt.payload = (uint8_t *)response;   //DOESN'T CHANGE THE PAYLOAD ADDRESS
          ESP_LOGI(TAG, "payload pointer: %p response pointer: %p", &ws_pkt.payload, response);
          ret = httpd_ws_send_frame(req, &ws_pkt);
    }

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Can i point the websocket payload to another memory location ?

Postby MicroController » Wed Aug 20, 2025 11:31 am

Question about ws_echo_server example in http_server directory
...
In the example the response uses in the same address for the payload.
Because it's an "echo server" which just sends back the payload it receives.

Code: Select all

    
          ESP_LOGI(TAG, "payload pointer: %p response pointer: %p", &ws_pkt.payload, response);
ws_pkt.payload is a pointer. You're taking the address of this pointer (= a pointer to a pointer) instead of its value (= a pointer) here.
Use

Code: Select all

ESP_LOGI(TAG, "payload pointer: %p response pointer: %p", ws_pkt.payload, response);
And don't forget to also set the payload length.

noweare
Posts: 101
Joined: Tue Jul 02, 2019 11:35 am

Re: Can i point the websocket payload to another memory location ?

Postby noweare » Wed Aug 20, 2025 12:56 pm

Thanks, I was forgetting to set the length.
Have a good day, Microcontroller : )

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot], meta-externalagent and 1 guest