Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
999 views
in Technique[技术] by (71.8m points)

stm32 - Simple TCP Communication

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_connectand Server initilize with: tcp_echoserver_init

What is my problem how can I solve this ?

enter image description here

/**
  * @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);
    }
  }
}

Client:

/**
  * @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);
  }  

}

I notice something, when I restart the Client device tcp_echoclient_connected callback doesnt call I dont know why?

question from:https://stackoverflow.com/questions/65933012/simple-tcp-communication

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...