• AVR Freaks

Hot!Problem sending chunked HTTP data using ATWINC1500

Author
larrycook99
New Member
  • Total Posts : 24
  • Reward points : 0
  • Joined: 2012/04/01 11:37:34
  • Location: Lexington, KY
  • Status: offline
2019/07/24 13:30:43 (permalink)
0

Problem sending chunked HTTP data using ATWINC1500

I am trying to learn how to use the AT WINC1500 using the Microchip Explorer 16 board and WINC1500 PicTail using the MLA code version v2018_11_26. Specifically I want to receive HTTP GET command and serve a web page using chunked data. If I send the HTTP response using a single call to the send() function things work as expected as the web browser that receives the response properly displays the web page data. This is true whether I send the data with known data length or as chunked data.
 
However, if I send the chunked data with two calls to send() then the page is not properly display by the web browser.

Anyone know how to send HTTP data using 2 calls to send()?
post edited by larrycook99 - 2019/07/24 13:32:31
#1

5 Replies Related Threads

    aschen0866
    Super Member
    • Total Posts : 4553
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Problem sending chunked HTTP data using ATWINC1500 2019/07/24 15:57:49 (permalink)
    0
    The maximum TCP transmit size is 1400-bytes (SOCKET_BUFFER_MAX_LENGTH). It is possible to call the send() API multiple times until SOCK_ERR_BUFFER_FULL is returned.
     
    I would run a Wireshark capture to verify the two TCP packets are sent. If two packets are there, then it is likely something wrong with your HTTP code.
    #2
    larrycook99
    New Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2012/04/01 11:37:34
    • Location: Lexington, KY
    • Status: offline
    Re: Problem sending chunked HTTP data using ATWINC1500 2019/07/25 08:04:03 (permalink)
    0
    I appreciate the repy.
     
    What I have in my code is three strings defined:
     
    #define TCP_SEND_MESSAGE_1 "HTTP/1.1 200 OK\r\nTransfer-Encoding: Chunked\r\nConnection: Close\r\nContent-Type: text/html\r\n\r\n007\r\n<html>\r\n\r\n"
    #define TCP_SEND_MESSAGE_2 "027\r\n<body><h1>It works!</h1></body></html>\r\n\r\n000\r\n\r\n"
    #define TCP_SEND_MESSAGE_3 TCP_SEND_MESSAGE_1 TCP_SEND_MESSAGE_2
     
    If I call send() with just TCP_SEND_MESSAGE_3, all is well. The browser displays a page with "It works!" displayed as expected.
     
    If instead I call send() twice, the first time with TCP_SEND_MESSAGE_1 and then with TCP_SEND_MESSAGE_2, the browser does not display the page as expected.
     
    As you can see, TCP_SEND_MESSAGE_3 is just TCP_SEND_MESSAGE_1 and TCP_SEND_MESSAGE_2 appended together, so I expected both to work, but they don't and I don't understand why.
    #3
    aschen0866
    Super Member
    • Total Posts : 4553
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Problem sending chunked HTTP data using ATWINC1500 2019/07/26 11:02:26 (permalink)
    0
    I think you need to remove the extra CRLF before the 0-size chunk. 
    #4
    aschen0866
    Super Member
    • Total Posts : 4553
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Problem sending chunked HTTP data using ATWINC1500 2019/07/26 11:03:18 (permalink)
    #5
    larrycook99
    New Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2012/04/01 11:37:34
    • Location: Lexington, KY
    • Status: offline
    Re: Problem sending chunked HTTP data using ATWINC1500 2019/07/27 20:33:31 (permalink)
    0
    I figured out the problem. The original example looked like:
     
    static t_msg_send msg_tcp_send = {TCP_SEND_MESSAGE};
    ...
    send(tcp_client_socket, &msg_tcp_send, sizeof(TCP_SEND_MESSAGE), 0);
    ...
     
    So to see how to do chunked data with multiple calls to send() I just copied the original code like so:
     
    static t_msg_send msg_tcp_send = {TCP_SEND_MESSAGE_1};
    static t_msg_send msg_tcp_send_2 = {TCP_SEND_MESSAGE_2};
    ...
    send(tcp_client_socket, &msg_tcp_send, sizeof(TCP_SEND_MESSAGE_1), 0);
    send(tcp_client_socket, &msg_tcp_send_2, sizeof(TCP_SEND_MESSAGE_2), 0);
    ...
     
    Because the code was using sizeof(), a NULL was being inserted at the end of TCP_SEND_MESSAGE_1 which was in the middle of the reconstructed HTTP response and therefore made the response not valid. Using strlen() instead or just subtracting 1 from sizeof() solved the problem.
     
    The original example worked because the NULL at the end of the HTTP payload had no effect on the HTTP parsing.
     
    Your Wireshark capture helped me figure this out because when I compared my Wireshark to yours is when I noticed the NULLs. So thank you for your efforts.
    #6
    Jump to:
    © 2020 APG vNext Commercial Version 4.5