<?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 Problem sending TCP socket in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problem-sending-TCP-socket/m-p/211196#M5219</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I'm very new to the MQX RTCS stack, and writing embedded web clients in general, so I would greatly appreciate some guidance on this issue I'm having.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using CodeWarrior 10 with MQX3.6, and have the web_hvac demo working fine on a TWR52259 platform.&amp;nbsp; I'm trying to add functionality to post database entries to a web server.&amp;nbsp; To start I created a new shell command ("test") and added the following code that calls socket, bind, connect, and send.&amp;nbsp; This is based on the MQX RTCS User Guide, and the sample code.&amp;nbsp; I couldn't find much else in the forum or elsewhere online.&amp;nbsp; When I call the function from the shell I get error code 0x1704, which is RTCSERR_SOCK_INVALID.&amp;nbsp; The shell output follows the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;int_32  Shell_test(int_32 argc, char_ptr argv[] )  {   boolean           print_usage, shorthelp = FALSE;   int_32            return_code = SHELL_EXIT_SUCCESS;   uint_32 new_socket;   sockaddr_in local_sin, remote_sin;   uint_32 result;   uint_16 namelen;      char buffer[50], resp_buffer[50];      print_usage = Shell_check_help_request(argc, argv, &amp;amp;shorthelp );   if (!print_usage)  {      if (argc &amp;gt; 1) {         printf("Error, invalid number of parameters\n");         return_code = SHELL_EXIT_ERROR;         print_usage=TRUE;      } else {          printf("Trying to send message to &lt;A href="http://www.google.ca" rel="nofollow noopener noreferrer" target="_blank"&gt;www.google.ca&lt;/A&gt;\n");                  new_socket = socket(AF_INET, SOCK_STREAM, 0);         if (new_socket == RTCS_SOCKET_ERROR) {          printf("RTCS_SOCKET_ERROR\n");          return;         } else {             printf ("Socket opened: %d\n", new_socket);         }                     memset((char *) &amp;amp;local_sin, 0, sizeof(sockaddr_in));         local_sin.sin_family = AF_INET;         local_sin.sin_port = 0;         local_sin.sin_addr.s_addr = ENET_IPADDR;//INADDR_ANY;         result = bind(new_socket, &amp;amp;local_sin, sizeof (sockaddr_in));         if (result != RTCS_OK){          printf("Error, bind() failed with error code %lx\n", result);          return;         }    printf ("Socket bound...\n");   namelen = sizeof (sockaddr_in);   result = getsockname(new_socket, &amp;amp;local_sin, &amp;amp;namelen);   if (result != RTCS_OK) {    printf("Error, getsockname() failed with error code %lx\n", result);   } else {    printf("Local address family is %x\n", local_sin.sin_family);    printf("Local port is %d\n", local_sin.sin_port);    printf("Local IP address is %lx\n", local_sin.sin_addr.s_addr);   }                  memset((char *) &amp;amp;remote_sin, 0, sizeof(sockaddr_in));         remote_sin.sin_family = AF_INET;         remote_sin.sin_port = 80;         remote_sin.sin_addr.s_addr = 0xADC22168;    //173.194.33.104   (google.ca)         result = connect(new_socket, &amp;amp;remote_sin, sizeof (sockaddr_in));         if (result != RTCS_OK){          printf("Error, connect() failed with error code %lx\n", result);          return;         }         printf("Connected to %lx, port %d.\n", remote_sin.sin_addr.s_addr, remote_sin.sin_port);                  strcpy (buffer, "GET index.html HTTP/1.0\n\n");         printf ("Outgoing message len: %d, string: %s\n", strlen(buffer) + 1, buffer);                  result = send(new_socket, buffer, strlen(buffer) + 1, 0);         if (result != RTCS_OK){          printf("Error, send() failed with error code %lx\n", RTCS_geterror(result));          shutdown(new_socket, FLAG_CLOSE_TX);          return;         }         printf("Sent %d bytes.\n", result);                  result = recv(new_socket, resp_buffer, 50, 0);         if (result == RTCS_ERROR){    printf("Error, recv() failed with error code %lx\n", RTCS_geterror(new_socket));         } else {          printf("Received %ld bytes of data.\n%s\n", result, buffer);         }               }   }      if (print_usage)  {      if (shorthelp)  {         printf("%s \n", argv[0]);      } else  {         printf("Usage: %s \n", argv[0]);      }   }   return return_code;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;shell&amp;gt; testTrying to send message to &lt;A href="http://www.google.ca" rel="nofollow noopener noreferrer" target="_blank"&gt;www.google.ca&lt;/A&gt;Socket opened: 536880972Socket bound...Local address family is 1Local port is 5000Local IP address is a9fe0303Connected to adc22168, port 80.Outgoing message len: 26, string: GET index.html HTTP/1.0Error, send() failed with error code 1704shell&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone see what I'm doing wrong here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Angelo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 06 Jul 2010 00:27:08 GMT</pubDate>
    <dc:creator>ARQuattr</dc:creator>
    <dc:date>2010-07-06T00:27:08Z</dc:date>
    <item>
      <title>Problem sending TCP socket</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problem-sending-TCP-socket/m-p/211196#M5219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I'm very new to the MQX RTCS stack, and writing embedded web clients in general, so I would greatly appreciate some guidance on this issue I'm having.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using CodeWarrior 10 with MQX3.6, and have the web_hvac demo working fine on a TWR52259 platform.&amp;nbsp; I'm trying to add functionality to post database entries to a web server.&amp;nbsp; To start I created a new shell command ("test") and added the following code that calls socket, bind, connect, and send.&amp;nbsp; This is based on the MQX RTCS User Guide, and the sample code.&amp;nbsp; I couldn't find much else in the forum or elsewhere online.&amp;nbsp; When I call the function from the shell I get error code 0x1704, which is RTCSERR_SOCK_INVALID.&amp;nbsp; The shell output follows the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;int_32  Shell_test(int_32 argc, char_ptr argv[] )  {   boolean           print_usage, shorthelp = FALSE;   int_32            return_code = SHELL_EXIT_SUCCESS;   uint_32 new_socket;   sockaddr_in local_sin, remote_sin;   uint_32 result;   uint_16 namelen;      char buffer[50], resp_buffer[50];      print_usage = Shell_check_help_request(argc, argv, &amp;amp;shorthelp );   if (!print_usage)  {      if (argc &amp;gt; 1) {         printf("Error, invalid number of parameters\n");         return_code = SHELL_EXIT_ERROR;         print_usage=TRUE;      } else {          printf("Trying to send message to &lt;A href="http://www.google.ca" rel="nofollow noopener noreferrer" target="_blank"&gt;www.google.ca&lt;/A&gt;\n");                  new_socket = socket(AF_INET, SOCK_STREAM, 0);         if (new_socket == RTCS_SOCKET_ERROR) {          printf("RTCS_SOCKET_ERROR\n");          return;         } else {             printf ("Socket opened: %d\n", new_socket);         }                     memset((char *) &amp;amp;local_sin, 0, sizeof(sockaddr_in));         local_sin.sin_family = AF_INET;         local_sin.sin_port = 0;         local_sin.sin_addr.s_addr = ENET_IPADDR;//INADDR_ANY;         result = bind(new_socket, &amp;amp;local_sin, sizeof (sockaddr_in));         if (result != RTCS_OK){          printf("Error, bind() failed with error code %lx\n", result);          return;         }    printf ("Socket bound...\n");   namelen = sizeof (sockaddr_in);   result = getsockname(new_socket, &amp;amp;local_sin, &amp;amp;namelen);   if (result != RTCS_OK) {    printf("Error, getsockname() failed with error code %lx\n", result);   } else {    printf("Local address family is %x\n", local_sin.sin_family);    printf("Local port is %d\n", local_sin.sin_port);    printf("Local IP address is %lx\n", local_sin.sin_addr.s_addr);   }                  memset((char *) &amp;amp;remote_sin, 0, sizeof(sockaddr_in));         remote_sin.sin_family = AF_INET;         remote_sin.sin_port = 80;         remote_sin.sin_addr.s_addr = 0xADC22168;    //173.194.33.104   (google.ca)         result = connect(new_socket, &amp;amp;remote_sin, sizeof (sockaddr_in));         if (result != RTCS_OK){          printf("Error, connect() failed with error code %lx\n", result);          return;         }         printf("Connected to %lx, port %d.\n", remote_sin.sin_addr.s_addr, remote_sin.sin_port);                  strcpy (buffer, "GET index.html HTTP/1.0\n\n");         printf ("Outgoing message len: %d, string: %s\n", strlen(buffer) + 1, buffer);                  result = send(new_socket, buffer, strlen(buffer) + 1, 0);         if (result != RTCS_OK){          printf("Error, send() failed with error code %lx\n", RTCS_geterror(result));          shutdown(new_socket, FLAG_CLOSE_TX);          return;         }         printf("Sent %d bytes.\n", result);                  result = recv(new_socket, resp_buffer, 50, 0);         if (result == RTCS_ERROR){    printf("Error, recv() failed with error code %lx\n", RTCS_geterror(new_socket));         } else {          printf("Received %ld bytes of data.\n%s\n", result, buffer);         }               }   }      if (print_usage)  {      if (shorthelp)  {         printf("%s \n", argv[0]);      } else  {         printf("Usage: %s \n", argv[0]);      }   }   return return_code;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;shell&amp;gt; testTrying to send message to &lt;A href="http://www.google.ca" rel="nofollow noopener noreferrer" target="_blank"&gt;www.google.ca&lt;/A&gt;Socket opened: 536880972Socket bound...Local address family is 1Local port is 5000Local IP address is a9fe0303Connected to adc22168, port 80.Outgoing message len: 26, string: GET index.html HTTP/1.0Error, send() failed with error code 1704shell&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone see what I'm doing wrong here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Angelo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jul 2010 00:27:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problem-sending-TCP-socket/m-p/211196#M5219</guid>
      <dc:creator>ARQuattr</dc:creator>
      <dc:date>2010-07-06T00:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem sending TCP socket</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problem-sending-TCP-socket/m-p/211197#M5220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;problem is with&amp;nbsp; send() because return value are 1)&amp;nbsp;Number of bytes sent 2)&amp;nbsp; RTCS_ERROR&lt;/P&gt;&lt;P&gt;and the second problem is RTCS_geterror have parameter socket [in] — Socket handle , in your example is it new_socket .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;result = send(new_socket,buffer, strlen(buffer) + 1, 0);
             if (result == RTCS_ERROR){
                 printf("Error, send() failed with error code %lx\n", RTCS_geterror(new_socket));
                 shutdown(new_socket, FLAG_CLOSE_TX);
                 return 1;
             }&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 20:10:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problem-sending-TCP-socket/m-p/211197#M5220</guid>
      <dc:creator>sajmon</dc:creator>
      <dc:date>2012-03-29T20:10:25Z</dc:date>
    </item>
  </channel>
</rss>

