3

我使用 lwip 作为客户端从服务器执行 HTTP GET。我希望收到的文件大约是 75kB。我正确地得到了第一个〜9kB,但没有更多的数据到达。每个到达堆栈的数据包都被正确地确认。

为了缩短一长段代码,我将 netconn 接口与以下命令一起使用。在几个数据包到达之前没有给出错误,在此之后 netconn_recv 开始给出超时,直到大约 15 分钟后服务器发送一个数据包以关闭连接(这告诉我连接至少在某种意义上仍在工作)。

#define HTTP_GET_TEMPLATE "GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n"

addr = <the ip address I'm talking to>
location = <location of the filename on the host>
host = <hostname>

upg = netconn_new(NETCONN_TCP);
netconn_set_recvtimeout(upg, 30000);
err = netconn_bind(upg, IP_ADDR_ANY, 0);
err = netconn_connect(upg, &addr, 80);
sprintf(request, HTTP_GET_TEMPLATE, location, host);
siRc = netconn_write(upg, request, (strlen(request)+1)*sizeof(char), NETCONN_COPY);
while (true)
{
    err = netconn_recv(upg, &netbuf);
    if (ERR_IS_FATAL(err))
    {
        break;
    }
    if (err == ERR_OK)
    {
        do
        {
            err = netbuf_data(netbuf, &data, &len);
            < handle the data in "data">
        } while (netbuf_next(netbuf) >= 0);

        netbuf_delete(netbuf);
    }
}

谁能给我任何下一步尝试的提示?谢谢

4

0 回答 0