Websocket is not properly reciving

A_A1990
Posts: 1
Joined: Sun Sep 03, 2023 9:05 am

Websocket is not properly reciving

Postby A_A1990 » Sun Sep 03, 2023 10:54 am

i'm using a websocket server. I have initialized it following a tutorial. The websocket sends a timestamp every 3 seconds and receives text asynchronously. Sending is going very well. However, receiving print strange values or giving errors.

I'm using esp32s3.
esp-idf version 5.1.

I have used Postman to receive and send data. In addition of some extensions on Chrome.

I have used Wireshark to analyze the data. It shows that messages from ESP are not masked, and messages sending to ESP are masked.

My code as follow:

Code: Select all

tatic esp_err_t on_ws_url(httpd_req_t *r)
{
    ESP_LOGI("ES","URL: %s",r->uri);
    client_session_id = httpd_req_to_sockfd(r);
    websocket_closed = false;
    if(r->method == HTTP_GET){
        return ESP_OK;
    }
    
    httpd_ws_frame_t ws_pkt;
    memset(&ws_pkt,0,sizeof(httpd_ws_frame_t()));
    ws_pkt.type = HTTPD_WS_TYPE_TEXT;
    
    ws_pkt.payload = malloc(WS_MAX_SIZE);
    httpd_ws_recv_frame(r,&ws_pkt,WS_MAX_SIZE);
    
    printf("Web_socket: %.*s\n", ws_pkt.len,ws_pkt.payload);
    free(ws_pkt.payload);
    
   
Errors are:
  • Failed to read header byte (socket FD invalid), closing socket now
    Failed to receive payload
    httpd_ws_recv_frame: WS frame is not properly masked.
In the attachment is a screenshot of the random output, I'm sending the same message "hello".
So, it is a kind of random error.

I want to know if the problem is from my code or if it is from the library.
Any suggestions?
Attachments
Capture.PNG
Capture.PNG (28.3 KiB) Viewed 600 times

Who is online

Users browsing this forum: Bing [Bot] and 119 guests