Websocket is not properly reciving
Posted: 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:
Errors are:
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?
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);
- 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.
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?