Retries do not work with UdpClient · Issue #155 · NModbus/NModbus · GitHub
Skip to content

Retries do not work with UdpClient #155

Description

@Jeroen6

It looks like the retries do not work when using an UdpClient.
UdpClient throws an SocketError since it throws a SocketException when there is a read timeout of the acknowledge due to packet loss.

   at System.Net.Sockets.Socket.Receive(Byte[] buffer)
   at NModbus.IO.UdpClientAdapter.Read(Byte[] buffer, Int32 offset, Int32 count) in ...NModbus-3.0.80\NModbus\IO\UdpClientAdapter.cs:line 87
   at NModbus.IO.ModbusIpTransport.ReadRequestResponse(IStreamResource streamResource, IModbusLogger logger) in ...NModbus-3.0.80\NModbus\IO\ModbusIpTransport.cs:line 36
   at NModbus.IO.ModbusIpTransport.ReadResponse[T]() in ...NModbus-3.0.80\NModbus\IO\ModbusIpTransport.cs:line 142
   at NModbus.IO.ModbusTransport.UnicastMessage[T](IModbusMessage message) in ...NModbus-3.0.80\NModbus\IO\ModbusTransport.cs:line 137
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Right now this walks falls through the retries to the throw at line 198.

I can make it work with an additional e is SocketException in the if() at L189

Is this a viable fix?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions