<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic HTTP Client in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/HTTP-Client/m-p/714473#M17592</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;I wanted to create a HTTP client which can send request to and receive response from server using TWR-K60 and&lt;/P&gt;&lt;P&gt;TWR-SER2 tower boards with MQX RTOS 4.2.&lt;/P&gt;&lt;P&gt;I found this thread:&amp;nbsp;&lt;A href="https://community.nxp.com/thread/309350"&gt;TCP / IP Socket Client Issue (RTCS bug?)&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on the reference code attached with the above thread, i tried to setup the HTTP client and it worked for me.&lt;/P&gt;&lt;P&gt;-----------&lt;/P&gt;&lt;P&gt;But I would like to know, can I perform send() and receive() for multiple time&amp;nbsp;by opening Socket connection only once?&lt;/P&gt;&lt;P&gt;(open connection only once, perform request/response multiple time, close the connection at the end)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_13.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/6656i32072BE327C3DB59/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_13.png" alt="pastedImage_13.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tried to debug the code and observed the TCP connection state (tcb-&amp;gt;state) as follow:&lt;/P&gt;&lt;P&gt;bind() --&amp;gt; connect()&lt;/P&gt;&lt;P&gt;[ tcb-&amp;gt;state = 1(i.e. SYN_SENT) after successful ACK, tcb-&amp;gt;state = 3(i.e. ESTABLISHMENT)]&lt;/P&gt;&lt;P&gt;Send request -- send()&amp;nbsp; [tcb-&amp;gt;state remains 3]&lt;/P&gt;&lt;P&gt;Receive response -- recv() [After receiving response tcb -&amp;gt;state changed to 6 (i.e. CLOSE_WAIT)]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, if I try to send another request, its unsuccessful, because server is in CLOSE_WAIT state.&lt;/P&gt;&lt;P&gt;Is there any API to keep server in ESTABLISHMENT state until&amp;nbsp;Client closes the connection?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your help will be really appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 Sep 2017 16:53:13 GMT</pubDate>
    <dc:creator>priyagupta</dc:creator>
    <dc:date>2017-09-27T16:53:13Z</dc:date>
    <item>
      <title>HTTP Client</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/HTTP-Client/m-p/714473#M17592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;I wanted to create a HTTP client which can send request to and receive response from server using TWR-K60 and&lt;/P&gt;&lt;P&gt;TWR-SER2 tower boards with MQX RTOS 4.2.&lt;/P&gt;&lt;P&gt;I found this thread:&amp;nbsp;&lt;A href="https://community.nxp.com/thread/309350"&gt;TCP / IP Socket Client Issue (RTCS bug?)&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on the reference code attached with the above thread, i tried to setup the HTTP client and it worked for me.&lt;/P&gt;&lt;P&gt;-----------&lt;/P&gt;&lt;P&gt;But I would like to know, can I perform send() and receive() for multiple time&amp;nbsp;by opening Socket connection only once?&lt;/P&gt;&lt;P&gt;(open connection only once, perform request/response multiple time, close the connection at the end)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_13.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/6656i32072BE327C3DB59/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_13.png" alt="pastedImage_13.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tried to debug the code and observed the TCP connection state (tcb-&amp;gt;state) as follow:&lt;/P&gt;&lt;P&gt;bind() --&amp;gt; connect()&lt;/P&gt;&lt;P&gt;[ tcb-&amp;gt;state = 1(i.e. SYN_SENT) after successful ACK, tcb-&amp;gt;state = 3(i.e. ESTABLISHMENT)]&lt;/P&gt;&lt;P&gt;Send request -- send()&amp;nbsp; [tcb-&amp;gt;state remains 3]&lt;/P&gt;&lt;P&gt;Receive response -- recv() [After receiving response tcb -&amp;gt;state changed to 6 (i.e. CLOSE_WAIT)]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, if I try to send another request, its unsuccessful, because server is in CLOSE_WAIT state.&lt;/P&gt;&lt;P&gt;Is there any API to keep server in ESTABLISHMENT state until&amp;nbsp;Client closes the connection?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your help will be really appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Sep 2017 16:53:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/HTTP-Client/m-p/714473#M17592</guid>
      <dc:creator>priyagupta</dc:creator>
      <dc:date>2017-09-27T16:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: HTTP Client</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/HTTP-Client/m-p/714474#M17593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp; &lt;A _jive_internal="true" data-content-finding="Community" data-userid="291111" data-username="priyagupta" href="https://community.nxp.com/people/priyagupta"&gt;Priyab&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, TCP socket should work as you described, (open connection only once, perform request/response multiple time, close the connection at the end). You can debug with MQX TAD.&lt;/P&gt;&lt;P&gt;Can you attach your modified code (server and client) for further analyzing?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Sep 2017 11:57:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/HTTP-Client/m-p/714474#M17593</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2017-09-29T11:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: HTTP Client</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/HTTP-Client/m-p/714475#M17594</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Daniel,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to mention that I am working with cloud based server(project specific), so i haven't done any&amp;nbsp;server implementation.&lt;/P&gt;&lt;P&gt;Attached is the http client code with request and response Log.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have few more questions regarding the recv() function behavior:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. recv() returns value '0' for initial few seconds and later it returns the actual response content length.&amp;nbsp;I added socket option 'OPT_RECEIVE_TIMEOUT' with value =&amp;nbsp;10000.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Do i need to program&amp;nbsp;any other socket options as well?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; To come over this issue, I added recv() function in while loop till the returned value is '0'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. After reading response for 1st time, if i try to read the response again, I am getting return value(tmpres) = '-1' and error code as 0x1638 (i.e. connection closing), but I am expecting to get value = '0' (i.e. no more data to be read). Why is it so?&lt;/P&gt;&lt;P&gt;(Below is the snippet of recv() function)&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;memset(recvBuf, 0, sizeof(recvBuf) );&lt;/P&gt;&lt;P&gt;while ((tmpres = recv(sockets.sock4, recvBuf, sizeof(recvBuf), 0)) == 0);&lt;BR /&gt; do&lt;BR /&gt; {&lt;BR /&gt; numBytes += tmpres;&lt;BR /&gt; recvBuf[tmpres] = 0; /* for test assuming receiving a html page, this can be printed */&lt;BR /&gt; printf("%s\n",recvBuf);&lt;/P&gt;&lt;P&gt;printf("Packet received of %d Bytes Total Bytes Received %d\n",tmpres,numBytes);&lt;BR /&gt; &lt;BR /&gt; tmpres = recv(sockets.sock4, recvBuf, sizeof(recvBuf), 0);&lt;BR /&gt; }while(tmpres &amp;gt; 0);&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know, how can I overcome these issues..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Priya&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Sep 2017 23:29:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/HTTP-Client/m-p/714475#M17594</guid>
      <dc:creator>priyagupta</dc:creator>
      <dc:date>2017-09-29T23:29:49Z</dc:date>
    </item>
  </channel>
</rss>

