Из цитаты следует, что длина сообщения модбас может быть объявлена
только в заголовке. И раскопал интересную претензию от пользователя
к производителю оборудования - пользователь жалуется, что
оборудование не пропускает несколько модбас сообщений в одном
пакете TCP (ссылка): https://community.teltonika-networks.com/24927/rut240-modbus-handle-multiple-modbus-requests-single-packet
По ходу обсуждения (приведу здесь цитатаы, вдруг ссылка протухнет):
Пользователь:
This matches what I said above. Many modbus messages may be sent in one TCP/IP packet. Or they might happen to be split up at random places and arrive in multiple separate chunks (albeit in order). It's up to the application implementation to handle this.
Currently sending multiple Modbus ADUs, even if as separate TCP/IP packets (ensured by for example disabling Nagle's algorithm on the sending side), results in the router closing the connection. I believe this goes against the Modbus TCP specification allowing multiple requests in-flight at the same time. Besides, that's the transcation identifier is for.
Производитель:
Yes, but in the same specification implementation rules it advised not to go with multiple requests in same TCP PDU.
"A TCP frame must transport only one MODBUS ADU. It is advised against sending multiple MODBUS requests or responses on the same TCP PDU"
The connection closing was implemented to avoid situation, when single client occupies router Modbus slave and prevents other clients to established connection. Of course if user want to persist connection, it can enable this in Modbus TCP slave window.
A TCP frame must transport only one MODBUS ADU. It is advised against sending multiple MODBUS requests or responses on the same TCP PDU
HTH.