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:53 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);
    }

nopnop2002
Posts: 359
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

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

Postby nopnop2002 » Sun Aug 24, 2025 11:14 pm

You probably need to specify the payload size correctly.

Code: Select all

ws_pkt.payload = malloc(size);
ws_pkt.len = size;
ret = httpd_ws_send_frame(req, &ws_pkt);
free(ws_pkt.payload);

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

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

Postby noweare » Fri Aug 29, 2025 1:48 pm

Yes, that was the problem.
Thank you.

Who is online

Users browsing this forum: Amazon [Bot] and 2 guests