cancel
Showing results for 
Search instead for 
Did you mean: 

Simple TCP Communication

DCtech
Associate II

I am trying to use basic TCP-IP communication with two different stm32 devices, one of them TCP client one of them TCP server. On the wireshark picture; Up to the arrow mark both client and server connection successfully data send and receive, after the arrow I reset the client than ReTransmition message shows. I am using stm32 lwip Raw, And simple CubeIde tcp-echo server client example.

Client initilized with 

tcp_echoclient_connect

and Server initilize with: 

tcp_echoserver_init

https://i.stack.imgur.com/eBfsp.png

/**
  * @brief  Initializes the tcp echo server
  * @param  None
  * @retval None
  */
void tcp_echoserver_init(void)
{
  /* create new tcp pcb */
  tcp_echoserver_pcb = tcp_new();
 
  if (tcp_echoserver_pcb != NULL)
  {
    err_t err;
 
    /* bind echo_pcb to port 7 (ECHO protocol) */
    err = tcp_bind(tcp_echoserver_pcb, IP_ADDR_ANY, 7);
 
    if (err == ERR_OK)
    {
      /* start tcp listening for echo_pcb */
      tcp_echoserver_pcb = tcp_listen(tcp_echoserver_pcb);
 
      /* initialize LwIP tcp_accept callback function */
      tcp_accept(tcp_echoserver_pcb, tcp_echoserver_accept);
    }
    else
    {
      /* deallocate the pcb */
      memp_free(MEMP_TCP_PCB, tcp_echoserver_pcb);
    }
  }
}
/**
  * @brief  Connects to the TCP echo server
  * @param  None
  * @retval None
  */
void tcp_echoclient_connect(void)
{
  ip_addr_t DestIPaddr;
  /* create new tcp pcb */
 
  echoclient_pcb = tcp_new();
 
  if (echoclient_pcb != NULL)
  {
    IP4_ADDR(&DestIPaddr, (uint8_t)192, (uint8_t)168, (uint8_t)1, (uint8_t)40);
    /* connect to destination address/port */
    tcp_connect(echoclient_pcb,&DestIPaddr,7,tcp_echoclient_connected);
  }
  else
  {
    SerialPrint("not null");
    memp_free(MEMP_TCP_PCB, echoclient_pcb);
  }  
}

What is my problem how can I solve this ?

2 REPLIES 2

Thank you for your suggestion but what is the connection with these link and my question. I've already working ethernet interface and lwip library. My problem is in TCP communication source code.