cancel
Showing results for 
Search instead for 
Did you mean: 

TCP Client Problem

afra
Associate

Hi

I'm using netconn api library to make tcp server and client on stm32f746

Tcp server works properly but client can not connect to server and it returns error code -4 (err1) which means routing problem

I don't understand the reason

here is my code

struct netconn *conn, *newconn;

   err_t err, recv_err, err1;

   struct netbuf *buf, *mybuf;

   ip_addr_t DestIPaddr;

   ip_addr_t LocalIPaddr;

   ip_addr_t ipaddr_server;

   ip_addr_t ipaddr_client;

   static unsigned short port;

   char *data;

 /* Create a new TCP connection handle */

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

 if (conn!= NULL)

 {

      IP4_ADDR(&DestIPaddr,192,168,1,31);

      err1 = netconn_connect(conn, &DestIPaddr,8234);

      printf("%d",err1);

      netconn_bind(conn, &ipaddr_client, 3262);

      if (err1 == ERR_OK)

      {

         /* Put the connection into LISTEN state */\

         printf("Hooray! %d",configUSE_TIME_SLICING);

         while(1)

         {

               mybuf = netbuf_new();

               data = netbuf_alloc(mybuf, 10);

               /* create some arbitrary data */

               for(int i = 0; i < 10; i++)

               {

                  data[i] = i;

               }

               /* send the arbitrary data */

               recv_err = netconn_recv(conn, &buf);

               if (recv_err == ERR_OK)

               {

                  data[0] ++;

               }

               err = netconn_send(conn, mybuf);

               if( err == ERR_OK)

               {

                  printf("send successfully");

               }

               netbuf_delete(mybuf);

               osDelay(1);      

         }

      }

  }

0 REPLIES 0