cancel
Showing results for 
Search instead for 
Did you mean: 

TCP Raw socket server

VSomasekhar
Associate II
  1. I am running a modified TCP Echo Server on the IO Board with STM32H723ZET6 MCU, and LWIP enabled on the Board. No RTOS used. I am sending a continuous sequence of Modbus requests from the ModPoll tool to the Modbus server running on the Board.  But the response contains both Echo Response and Modbus Response. I need to turn off the Echo Response and allow only the Modbus Response. Please mention how to modify the attached Echo Server for this purpose. The TCP Server is based on the source in the webpage: https://community.st.com/t5/stm32-mcus-embedded-software/how-to-send-data-lwip-tcp-server-to-client/td-p/119556  
  2. Is there any standard server source code is available using the LWIP TCP Raw Sockets, instead of an Echo Server?  I have attached the TCP Server Source code file. 
  3. Just for your reference, ModbusIxFace(..) function called in the TCP Server file, is given below:
  4. struct pbuf * ModbusIxFace(struct pbuf *p)

    {

    MBDEFS_BOOL mbHandle;

    struct pbuf *pTx = pbuf_alloc(Layer, TX_BUFFER_SIZE, bufType);

    mbHandle = HandleModbusRequest(p->payload);

    HAL_Delay(40);

    memcpy(pTx->payload, (void *)(QUERY_MESG_HEADER *)MBSlave_SendBuffer, sizeof(MBSlave_SendBuffer));

    //pIx = p;

    return pTx;

    }

    HandleModbusRequest(..) function receives the Modbus request packet and processes it.

    The Modbus request is built into the global byte array, MBSlave_SendBuffer[], and it is

    copied to the payload of a new packet buffer. All the Modbus protocol processing happens

    in the HandleModbusRequest(..) function.

    In the server code, it is needed to find a place, where I can check if it is echo or Modbus response. If it is echo response, I won't send it. If it is Modbus response, I'll send it. If any more details are required, I'll provide. Please help.

1 REPLY 1
ASEHST
ST Employee

Hello @VSomasekhar,

If I understand you correctly, you want to disable the Echo response and allow only the Modbus response on your TCP server. We propose modifying the tcp_echoserver_recv function in the tcp_echoserver.c file so that the ModbusIxFace function is called to handle the Modbus request. If ModbusIxFace returns a valid response, it is sent to the client. Otherwise, no Echo response is sent.

This modification can ensure that only Modbus responses are transmitted, thereby eliminating unwanted Echo responses.

 

With Regards,

 

If your question is answered, please close this topic by clicking "Accept as Solution".