Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何在同一个地址即实现http协议的数据请求又实现websocket的数据交互 (IDFGH-14219) #15016

Open
3 tasks done
cannnnnnnnnnnn opened this issue Dec 11, 2024 · 1 comment
Labels
Status: Opened Issue is new

Comments

@cannnnnnnnnnnn
Copy link

cannnnnnnnnnnn commented Dec 11, 2024

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

软件版本V5.3.1
我做出了以下修改

    httpd_uri_t init_server = {
        .uri = "/web", // 192.168.0.1
        .method = HTTP_GET,
        .handler = http_server_handler,
        .user_ctx = NULL,
        .is_websocket = true};
    httpd_register_uri_handler(server, &init_server);
static esp_err_t http_server_handler(httpd_req_t *req)
{
    if (req->method == HTTP_GET) {
        httpd_resp_send(req, (char *)WEB_HTML, HTTP_WEBPAGE_SIZE);
    }

    // 以下位websocket的数据解析
    httpd_ws_frame_t ws_pkt;
    uint8_t *buf = NULL;
    memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t));
    ws_pkt.type = HTTPD_WS_TYPE_BINARY;
    ........
    return ESP_OK;
}

在正常的http数据请求是没有问题html页面可以正常请求到数据,但是在websocket总是链接失败数据无法正确回复,接收数据参考ws_echo_server

esp_err_t ret = httpd_ws_recv_frame(req, &ws_pkt, 0);

ret = httpd_ws_send_frame(req, &ws_pkt);

I (54926) http_server: frame len is 2
I (54926) http_server: Got packet with message: ��
I (54926) http_server: Packet type: 0
W (54926) httpd_txrx: httpd_sock_err: error in send : 104
W (54936) httpd_ws: httpd_ws_send_frame_async: Failed to send WS header
E (54946) http_server: httpd_ws_send_frame failed with -1
W (54946) httpd_uri: httpd_uri: uri handler execution failed
W (59836) httpd_txrx: httpd_sock_err: error in send : 104
@espressif-bot espressif-bot added the Status: Opened Issue is new label Dec 11, 2024
@github-actions github-actions bot changed the title 如何在同一个地址即实现http协议的数据请求又实现websocket的数据交互 如何在同一个地址即实现http协议的数据请求又实现websocket的数据交互 (IDFGH-14219) Dec 11, 2024
@cannnnnnnnnnnn
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

No branches or pull requests

2 participants