<?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>MQX Software SolutionsのトピックProblems with recv() function</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-with-recv-function/m-p/198084#M4251</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I'm working with TWRK60N512, MQX 3.7. And a netbook with Linux RT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My embedded system is running as Server (Sockets TCP). It just runs a task:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="_jivemacro_uid_13482421984024715 jive_text_macro jive_macro_code" jivemacro_uid="_13482421984024715" modifiedtitle="true"&gt;
&lt;P&gt;s32BytesRecv = recv(u32SocketFd, au8BufferRx, MAX_LEN_BUFFER, 0);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;if(s32BytesRecv != RTCS_ERROR)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u16MsgCnt++;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My netbook is running as client, It sends 1000 messages of 4 bytes length each 50 ms.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problems is that when the MAX_LEN_BUFFER constant has the value of 4, no message is lost. But if MAX_LEN_BUFFER has a value greater than 4, then the system lose almost 50 % of messages.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea of how to resolve this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Edgar&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Sep 2012 15:44:04 GMT</pubDate>
    <dc:creator>edgarsevilla</dc:creator>
    <dc:date>2012-09-21T15:44:04Z</dc:date>
    <item>
      <title>Problems with recv() function</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-with-recv-function/m-p/198084#M4251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I'm working with TWRK60N512, MQX 3.7. And a netbook with Linux RT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My embedded system is running as Server (Sockets TCP). It just runs a task:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="_jivemacro_uid_13482421984024715 jive_text_macro jive_macro_code" jivemacro_uid="_13482421984024715" modifiedtitle="true"&gt;
&lt;P&gt;s32BytesRecv = recv(u32SocketFd, au8BufferRx, MAX_LEN_BUFFER, 0);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;if(s32BytesRecv != RTCS_ERROR)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u16MsgCnt++;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My netbook is running as client, It sends 1000 messages of 4 bytes length each 50 ms.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problems is that when the MAX_LEN_BUFFER constant has the value of 4, no message is lost. But if MAX_LEN_BUFFER has a value greater than 4, then the system lose almost 50 % of messages.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea of how to resolve this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Edgar&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2012 15:44:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-with-recv-function/m-p/198084#M4251</guid>
      <dc:creator>edgarsevilla</dc:creator>
      <dc:date>2012-09-21T15:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with recv() function</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-with-recv-function/m-p/198085#M4252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Edgar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could try setting the sockets options OPT_RECEIVE_NOWAIT. If the receive-nowait socket option is TRUE, RTCS immediately copies internally buffered data (up to buflen bytes) into the buffer (at buffer), and recv() returns. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The other option that could help is OPT_RECEIVE_PUSH. If the receive-push socket option is TRUE, a received TCP push flag causes recv() to return with whatever data has been received. If the receive-push socket option is FALSE, RTCS ignores incoming TCP push flags, and recv() returns when enough data has been received to fill the buffer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both options are linked with the buffer size you give to the socket. I hope this helps to solve your problem!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;BR /&gt;Garabo&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Oct 2012 13:54:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-with-recv-function/m-p/198085#M4252</guid>
      <dc:creator>Luis_Garabo</dc:creator>
      <dc:date>2012-10-19T13:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with recv() function</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-with-recv-function/m-p/198086#M4253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 11px; background-color: #ffffff;"&gt;I'm afraid this is incorrect usage of the recv() function. recv() function doen't necessarily return after a message. If we look into the RTCS User's Guide, we will see the recv() function returns when one of the following occurs: &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 11px; background-color: #ffffff;"&gt;-a push flag in the data is received &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 11px; background-color: #ffffff;"&gt;-buffer is completely filled with incoming data &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 11px; background-color: #ffffff;"&gt;-receive timeout expires &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 11px; background-color: #ffffff;"&gt;-immediately after it polls TCP for any data in the internal message buffer (also depends on socket options OPT_RECEIVE_NOWAIT and OPT_RECEIVE_PUSH). &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 11px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 11px; background-color: #ffffff;"&gt;recv() return value != RTCS_ERROR should not be counted as a complete TCP message. For example, I repeat your application scenario, with buffer size 100. On the K60N512 side I receive 4000 bytes (1000 times send() of 4 bytes on PC client side) with 82 recv() returns on MQX TCP Server side.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Oct 2012 10:41:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problems-with-recv-function/m-p/198086#M4253</guid>
      <dc:creator>Martin_</dc:creator>
      <dc:date>2012-10-23T10:41:26Z</dc:date>
    </item>
  </channel>
</rss>

