<?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のトピックRe: How do I create RTCS application with multiple concurrent connections?</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/How-do-I-create-RTCS-application-with-multiple-concurrent/m-p/490952#M15982</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Damon... you need Deamon :smileywink: (not a joke).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It consist of a parentServerTask that listens for connections. When a connection is stablished it creates a new childserverTask, but previously it detaches the socket to send it as parameter to the childTask. This way you will have a task for each connection and server will be always free for listening.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The main parts of the code are next:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void serverChildTask(uint_32 initial_data)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;listensock = socket(PF_INET, SOCK_STREAM, 0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;child_sock = accept(listensock, NULL, NULL);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Create a task to look after it */&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (RTCS_detachsock(child_sock) == RTCS_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = _task_create(0, SERVER_CHILD_TASK, child_sock);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (result == MQX_NULL_TASK_ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RTCS_attachsock(child_sock);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shutdown(child_sock, FLAG_CLOSE_TX);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("\nCould not create server child task.\n\r");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void serverChildTask(uint_32 initial_data)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint_32&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sock = initial_data;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sock = RTCS_attachsock(sock);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you consider this content solved your inquiry please mark it as correct answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Carlos&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Feb 2016 23:30:43 GMT</pubDate>
    <dc:creator>Carlos_Musich</dc:creator>
    <dc:date>2016-02-05T23:30:43Z</dc:date>
    <item>
      <title>How do I create RTCS application with multiple concurrent connections?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/How-do-I-create-RTCS-application-with-multiple-concurrent/m-p/490951#M15981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have created a Modbus TCP Server application as an MQX task, which runs over RTCS TCP/IP.&amp;nbsp; This task works very well for a single Modbus TCP Client connection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It detects a connection via accept(), receives Modbus command packets via recv() and sends Modbus response packets via send().&amp;nbsp; The task also uses closesocket() to close the connection, when either no Modbus Commands are received (timeout) or by detecting that the Modbus TCP Client has closed the connection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since accept() always blocks until a connection occurs, I can't easily modify my task to handle multiple concurrent connections.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the best (and simplest) way to handle multiple concurrent TCP connections on the same port (TCP port 502 in this case)?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Feb 2016 23:56:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/How-do-I-create-RTCS-application-with-multiple-concurrent/m-p/490951#M15981</guid>
      <dc:creator>DamonGibson</dc:creator>
      <dc:date>2016-02-04T23:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create RTCS application with multiple concurrent connections?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/How-do-I-create-RTCS-application-with-multiple-concurrent/m-p/490952#M15982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Damon... you need Deamon :smileywink: (not a joke).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It consist of a parentServerTask that listens for connections. When a connection is stablished it creates a new childserverTask, but previously it detaches the socket to send it as parameter to the childTask. This way you will have a task for each connection and server will be always free for listening.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The main parts of the code are next:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void serverChildTask(uint_32 initial_data)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;listensock = socket(PF_INET, SOCK_STREAM, 0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;child_sock = accept(listensock, NULL, NULL);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Create a task to look after it */&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (RTCS_detachsock(child_sock) == RTCS_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = _task_create(0, SERVER_CHILD_TASK, child_sock);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (result == MQX_NULL_TASK_ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RTCS_attachsock(child_sock);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shutdown(child_sock, FLAG_CLOSE_TX);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("\nCould not create server child task.\n\r");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void serverChildTask(uint_32 initial_data)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint_32&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sock = initial_data;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sock = RTCS_attachsock(sock);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you consider this content solved your inquiry please mark it as correct answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Carlos&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Feb 2016 23:30:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/How-do-I-create-RTCS-application-with-multiple-concurrent/m-p/490952#M15982</guid>
      <dc:creator>Carlos_Musich</dc:creator>
      <dc:date>2016-02-05T23:30:43Z</dc:date>
    </item>
  </channel>
</rss>

