cancel
Showing results for 
Search instead for 
Did you mean: 

LWIP and STM32F427 - disable echo back to client

Bogdan
Senior

Hello,

i have imported a tcp echo server example, using the old stdperiph code.

So far everything is working as expected.

Apart from the original code, i've implemented my own function to send a custom string.

But on the client side, for example if i send a comand string, i always get back the comand string and my custom response.

Is there a way to disable the echo transmition?

Here is my initialization code

 

 

 

int main(void)
{

	// stm32f427VGT6 - 256 kb RAM ; 1024kb Flash
	SetupClocks();
	setup_led_pins();
	DebugComPort_Init();
   /* configure ethernet (GPIOs, clocks, MAC, DMA) */
   printf("Program is starting....\r\n");
   ETH_BSP_Config();
   /* Initilaize the LwIP stack */
   LwIP_Init();
  
  /* tcp echo server Init */
   tcp_echoserver_init();
 
  /* Infinite loop */
  while (1)
  {  
    /* check if any packet received */
    if (ETH_CheckFrameReceived()) { 
      /* process received ethernet packet */
    	LwIP_Pkt_Handle();
    }
    /* handle periodic timers for LwIP */
    LwIP_Periodic_Handle(LocalTime);

    //Check ethernet link status
    if(LocalTime - checkLinkTime >= 1000)
    {
    	//read status register from PHY to check every second if the link is alive
    	if((ETH_ReadPHYRegister(DP83848_PHY_ADDRESS, 0x01) &0x04) != 0x04 )
    	{
    		printf("Link is lost....\r\n");
    	}
    	else
    	{
    		 GPIO_ToggleBits(GPIOD,GPIO_Pin_2); //moro - toggle a led
    	}
    	checkLinkTime=LocalTime;
    }
  }   
}

 

 

 

I also attached the tcp_echoserver.c file which contains the used functions

4 REPLIES 4
LCE
Principal

> But on the client side, for example if i send a comand string, i always get back the comand string and my custom response.

Isn't that what it's supposed to do?

Check your client side, it seems to use the same port number as the echo-port.

I think I remember that if you just "tcp_close()" the TCP-server, it will happily accept the next request from the client and "re-start", because the PCB gets back to LISTENING state.

Bogdan
Senior

Hello,

i am not very familiar with tcp ip protocols, but how to connect to the server if not using the predefined port?

So you mean that by default, a tcp server will echo what are you sending or?

In the end i am conecting from client side ( PC) to a server via a socket ip & port.  Then i send some comands to the server and expect to send back some predifined response.  My issue now, is that beside the predefined response, i firstly receive the comand which was initialy send by the client.

send: Measure 1 and i get   receive: Measure 1 , receive: Expected_Value

 

Bogdan
Senior

Hello,

i managed to see where the echo is sent back to the client.

Now i am a bit confused,  from the tcp_echoserver.c file, i see  the receive callback is  calling tcp_echoserver_recv , and inside of this  its called tcp_echoserver_send ( code listed bellow).

Normaly where shall i place the  information to be sent? I have placed a test string bellow instead of the original line

not used anymore - wr_err = tcp_write(tpcb, ptr->payload, ptr->len, 1);

used for test - wr_err = tcp_write(tpcb, stext,strlen(stext), TCP_WRITE_FLAG_COPY);

What do you think?

 

static void tcp_echoserver_send(struct tcp_pcb *tpcb, struct tcp_echoserver_struct *es)
{
  struct pbuf *ptr;
  err_t wr_err = ERR_OK;
 
 char stext[255] = "Just a test string";

  while ((wr_err == ERR_OK) &&
         (es->p != NULL) && 
         (es->p->len <= tcp_sndbuf(tpcb)))
  {
    
    /* get pointer on pbuf from es structure */
    ptr = es->p;

    /* enqueue data for transmission */
    //wr_err = tcp_write(tpcb, ptr->payload, ptr->len, 1);
    wr_err = tcp_write(tpcb, stext,strlen(stext), TCP_WRITE_FLAG_COPY);

    if (wr_err == ERR_OK) {
      u16_t plen;

      plen = ptr->len;
     
      /* continue with next pbuf in chain (if any) */
      es->p = ptr->next;
      
      if (es->p != NULL) {
        /* increment reference count for es->p */
        pbuf_ref(es->p);
      }
      
      /* free pbuf: will free pbufs up to es->p (because es->p has a reference count > 0) */
      pbuf_free(ptr);

      /* Update tcp window size to be advertized : should be called when received
      data (with the amount plen) has been processed by the application layer */
      tcp_recved(tpcb, plen);
   } else if(wr_err == ERR_MEM) {
      /* we are low on memory, try later / harder, defer to poll */
     es->p = ptr;
   } else {
     /* other problem ?? */
   }
  }
}

 

 

LCE
Principal

Sorry, not time to have a closer look, only this hint:

- no, TCP does not automatically echo

- you set up a TCP server on the STM32 with a port number

- the client needs to know the port number and connects to that server

- if your client connects to the echo port, everything should be echoed

- so you need another TCP server on the STM32 side with another port number (example: http uses port number 80) for your command interface, and your client needs to know that command port number