lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] HTTP packet cut in half


From: Darius Babrauskas
Subject: Re: [lwip-users] HTTP packet cut in half
Date: Wed, 5 Sep 2012 14:44:58 +0300

I dont like this: tcp_write(tpcb, htmlText, sizeof(htmlText), 0);

Maybe better:
tcp_write(tpcb, htmlText, sizeof(htmlText)-1, 0); or
tcp_write(tpcb, htmlText, strlen(htmlText), 0);



----- Original Message ----- From: "Tomáš Švec" <address@hidden>
To: "Mailing list for lwIP users" <address@hidden>
Sent: Wednesday, September 05, 2012 2:11 PM
Subject: [lwip-users] HTTP packet cut in half


Hello,

I am having trouble getting a webserver to work. My initial inspiration was
this simple RAW API example:
http://lists.gnu.org/archive/html/lwip-users/2008-06/msg00036.html .LWIP
version is 1.4.0. I successfully establish a TCP/IP connection, the chip
even sends a response to the request, but the packet observed in Wireshark
is "cut in half", which means a header is received with 6 bytes of 0 data
as HTTP and THEN comes the content in a separate packet, but without any
headers! (So the words "HTTP/1..." are considered MAC addresses, etc.) Here
is the simplified code:

static char htmlText[] =
"HTTP/1.0 200 OK\r\n\
Content-type: text/html\r\n\
\r\n\
<html> \
<head><title>Example project</title></head> \
<body> \
Hello, World! \
</body> \
</html>";

err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
       // This function is called after TCP/IP connection establishment
tcp_recv(pcb, http_receive);
return ERR_OK;
}

err_t http_receive(void * arg, struct tcp_pcb * tpcb, struct pbuf * p,
err_t err)
{
char *rq;
if (p != NULL)
{
rq = p->payload;
if (rq[0] == 'G' &&  rq[1] == 'E' && rq[2] == 'T' && rq[3] == ' ')
{
tcp_sent(tpcb, http_sent); // http_sent never gets called
tcp_write(tpcb, htmlText, sizeof(htmlText), 0);
}

tcp_recved(tpcb, p->len);

pbuf_free(p);
}
return ERR_OK;
}

Do you have any idea what's going on?

Best regards

Tomas



--------------------------------------------------------------------------------


_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users




reply via email to

[Prev in Thread] Current Thread [Next in Thread]