TCP/IP Client Send Block sent excess package

11 次查看(过去 30 天)
Hello Everyone, Good day.
I am running to SIMULINK block to communicate with external program using TCP. I noticed that my external program receive the wrong value, and I run Wireshark package capturer to check.
As shown in the Wireshark screencapture. Instead of a single package, it send four package (sometimes three, sometimes four). Because at the receiving end receives the data instaneously instead waiting for EOL. The SImulink send the wrong value. I have to note that the First Package contain the correct float value (I checked the Hex).
Does anyone have any idea why this happen? Thank you in advance for your attention.
  1 个评论
Danny Gho
Danny Gho 2022-2-15
As further information, I use the TCP/IP Receive and TCP/IP Send Block (Instrument Control).

请先登录,再进行评论。

回答(1 个)

Hornett
Hornett 2024-9-23
Hi Dany,
I understand you're facing an issue with TCP communication in Simulink where multiple packets are being sent instead of a single one, and this is causing problems with your external program's ability to correctly interpret the data. Let's go over some potential causes and solutions for this behavior:
  1. TCP Packet Fragmentation: TCP inherently breaks down data into smaller packets based on the Maximum Transmission Unit (MTU) of the network. If the data being sent exceeds the MTU, it will be fragmented into multiple packets. However, if you're seeing fragmentation for small amounts of data (like a single float), this is less likely to be the issue.
  2. Nagle's Algorithm: TCP uses an optimization algorithm called Nagle's algorithm, which can cause small packets to be buffered and sent together to reduce overhead. If your data is being sent as small packets, Nagle's algorithm might be causing the issue. Solution: You can try disabling Nagle's algorithm (TCP_NODELAY option) in the settings of your TCP block or external program.
  3. TCP Block Configuration: Check the configuration of your TCP Send/Receive blocks in Simulink. There might be settings related to packet size, buffering, or termination characters that are affecting how data is sent.Solution: Make sure that the 'Send size' parameter matches the size of the data you intend to send and that the 'Terminator' or 'EOL' parameter is correctly set if used.
  4. External Program Buffering: The external program might be reading from the TCP buffer as soon as data arrives without waiting for the expected amount of data or an EOL character. Solution: Modify the external program to read from the TCP buffer only after a certain amount of data has arrived or upon receiving an EOL character.
  5. Simulink Sample Time: If the Simulink model's sample time is too fast, it might be sending data in quick succession, which could be interpreted as separate packets. Solution: Adjust the sample time to ensure that data is sent at appropriate intervals.
  6. Wireshark Capture: Since you're using Wireshark, look at the details of the TCP packets. Check for the PUSH flag, which indicates that the sender is requesting the data be sent immediately. Also, analyze the timing between packets to see if there's a pattern that correlates with your Simulink model's behavior.
  7. External Program's TCP Stack: Investigate how the external program's TCP stack is configured. It might be set up to flush its buffer more frequently than necessary.Solution: Adjust the external program's TCP settings to better handle incoming data.
I hope this information helps

类别

Help CenterFile Exchange 中查找有关 Development Computer Setup 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by