Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Transport/BacnetIpUdpProtocolTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ private void Open()
_sharedConn = new UdpClient { ExclusiveAddressUse = false };
_sharedConn.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
var ep = new IPEndPoint(IPAddress.Any, SharedPort);
if (!string.IsNullOrEmpty(_localEndpoint)) ep = new IPEndPoint(IPAddress.Parse(_localEndpoint), SharedPort);
DisableConnReset(_sharedConn);
_sharedConn.Client.Bind(ep);
SetDontFragment(_sharedConn, _dontFragment);
Expand All @@ -109,19 +108,20 @@ private void Open()
{
var ep = new IPEndPoint(IPAddress.Any, ExclusivePort);
if (!string.IsNullOrEmpty(_localEndpoint)) ep = new IPEndPoint(IPAddress.Parse(_localEndpoint), ExclusivePort);
_exclusiveConn = new UdpClient(ep);

_exclusiveConn = new UdpClient { ExclusiveAddressUse = false };
_exclusiveConn.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
_exclusiveConn.Client.Bind(ep);
// Gets the Endpoint : the assigned Udp port number in fact
ep = (IPEndPoint)_exclusiveConn.Client.LocalEndPoint;
// closes the socket
_exclusiveConn.Close();
// Re-opens it with the freeed port number, to be sure it's a real active/server socket
// which cannot be disarmed for listen by .NET for incoming call after a few inactivity
// minutes ... yes it's like this at least on several systems
_exclusiveConn = new UdpClient(ep)
{
EnableBroadcast = true
};
_exclusiveConn = new UdpClient { ExclusiveAddressUse = false };
_exclusiveConn.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
_exclusiveConn.EnableBroadcast = true;
_exclusiveConn.Client.Bind(ep);
SetDontFragment(_exclusiveConn, _dontFragment);
DisableConnReset(_exclusiveConn);
}
Expand Down