cancel
Showing results for 
Search instead for 
Did you mean: 

TCP client error, TCP Port number reused -> STM32f417 + CubeMX + LWIP + RTOS + Netconn TCP client

PLang.4
Associate II

Hi All,

I have written simple TCP client using Netconn interface in LWIP on stm32f417 board. Client connects to LWIP server that is also on another stm32f417 board using Netconn api. After first succesfull TCP transmition, connection freezes, when connection with wireshark through switch that is mirroring port to PC I see ACK message from client after FIN ACK is sent from server. In some other workign TCP connection I see FIN ACK from server and then FIN ACK from client. So i think my client is should be not sending ACK message.

Question: Why is my client sending ACK message?

Thank You.

Peter

wireshark:

0693W000003PtXRQA0.png

void tcp_client_thread(void)

{

   struct netbuf *inbuf;

   char* buf;

   u16_t buflen;

   char jsonString[TCP_PACKET_LENGTH];

   struct netconn * conn;

   ip_addr_t ipaddr;

   ip_addr_t local;

   unsigned int   port_no = 50071;

   err_t          err2;

//   tcp_setup();

   UARTwrite("Application !!!: TCP client start !!!\n");

   IP4_ADDR(&local, 192, 168, 0, 70);

   IP4_ADDR(&ipaddr, 192, 168, 0, 30);                                        // Connection destination IP address

//   IP4_ADDR(&ipaddr, 192, 168, 0, 90);                                        // Connection destination IP address

   conn = netconn_new(NETCONN_TCP);                                       // create new TCP connection handle

   if (conn!= NULL) {

      err_t err1 = netconn_bind(conn, &local, port_no);

      if (err1 == ERR_OK) {

//         netconn_set_sendtimeout(conn, 1000);

//         netconn_set_recvtimeout(conn, 1000);

         err_t err2 = netconn_connect(conn, &ipaddr, 50030);

         // Connection destination port is 4000

         if(err2 == ERR_OK) {

//            HAL_GPIO_TogglePin(LED_B_GPIO_Port, LED_B_Pin);

            while(1) {

               jsonString[0] = 'D';

               jsonString[1] = '\0';

               err_t err3 = netconn_write(conn, jsonString, strlen((char*) jsonString), NETCONN_NOCOPY);

               if(err3 == ERR_OK) {

                  vTaskDelay(300);

                  err_t err4 = netconn_recv(conn, &inbuf);

                  if (err4 == ERR_OK)

                  {

                     if (netconn_err(conn) == ERR_OK)

                     {

                      netbuf_data(inbuf, (void**)&buf, &buflen);

                      HAL_GPIO_TogglePin(GPIOE, LED_G_Pin);

                      /* Is this an HTTP GET command? (only check the first 5 chars, since

                      there are other formats for GET, and we're keeping it very simple )*/

                      UARTwrite("Application !!!: TCP packet data received SUCCESS !!!\n");

                      //handleTCPpacket(conn, (const unsigned char*)buf, strlen(buf));

                     }

                     else{

                        UARTwrite("Application !!!: netconn ERR\n");

                     }

                  }

                  else{

                     UARTwrite("Application !!!: netconn_recv ERR\n");

                  }

               }

               else{

                  UARTwrite("Application !!!: netconn_write ERR\n");

               }

               break;

////               tcp_client_serve(conn);

//               if (conn->pcb.tcp->state == CLOSE_WAIT) {

//                  break;

//               }

            }

         }

         else{

            UARTwrite("Application !!!: netconn_connect ERR\n");

         }

      }

      else{

         UARTwrite("Application !!!: netconn_bind ERR\n");

      }

   }

   else {

      UARTwrite("Application !!!: netconn_new ERR\n");

   }

//   vTaskDelay(1500);

   netconn_close(conn);

//   vTaskDelay(300);

   netconn_delete(conn);                                                  // delete TCP connection handle

//   vTaskDelay(300);

   UARTwrite("Application !!!: TCP client Finish !!!\n");

}

1 REPLY 1
DCtech
Associate II

I get same problem did you solve it?