nanoMODBUS icon indicating copy to clipboard operation
nanoMODBUS copied to clipboard

Potential NAT issue

Open juanwinsor opened this issue 11 months ago • 2 comments

We are running a PLC simulator in a VM on a hardcoded IP address. We use NAT to bridge the host pc (which is running our modbus application), and the vm.

When I connect I receive a handful of timeouts and then it starts spitting out NMBS_ERROR_INVALID_TCP_MBAP error non stop. The logic triggering the error is the transaction id in the recv_res_header function

if (nmbs->platform.transport == NMBS_TRANSPORT_TCP) {
    if (nmbs->msg.transaction_id != req_transaction_id)
        return NMBS_ERROR_INVALID_TCP_MBAP;
}

Any help appreciated, thanks

juanwinsor avatar Jan 22 '25 14:01 juanwinsor

Hi, I don't think the NAT can cause any kind of alteration in the network packets. At first glance looks like maybe you are connecting to the wrong address or port and whatever server is on the other side is responding with something that the library is randomly interpreting as a message with invalid MBAP. Try do add a print or to debug that piece of code to understand what it is receiving as response.

debevv avatar Jan 23 '25 08:01 debevv

Hi, thanks for your reply.

I've verified its connecting to the correct server.

when i get a connected callback from my tcp socket, that is when i initiate polling (we have a setup on the actual subnet without nat, that is working). There does seem to be some sort of connection delay to the PLC simulator when we're connecting through nat, I start polling right away but get timeouts for my first few requests before the MBAP errors.

Edit: I was trying to handle my own timeout because unreal doesn't expose the timeout for the socket, which was messing things up.

juanwinsor avatar Jan 23 '25 18:01 juanwinsor