private void Open() { if (!m_exclusive_port) { /* We need a shared broadcast "listen" port. This is the 0xBAC0 port */ /* This will enable us to have more than 1 client, on the same machine. Perhaps it's not that important though. */ /* We (might) only recieve the broadcasts on this. Any unicasts to this might be eaten by another local client */ if (m_shared_conn == null) { m_shared_conn = new UdpClient(); m_shared_conn.ExclusiveAddressUse = false; m_shared_conn.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); EndPoint ep = new IPEndPoint(IPAddress.Any, m_port); if (!string.IsNullOrEmpty(m_local_endpoint)) { ep = new IPEndPoint(IPAddress.Parse(m_local_endpoint), m_port); } m_shared_conn.Client.Bind(ep); m_shared_conn.DontFragment = m_dont_fragment; } /* This is our own exclusive port. We'll recieve everything sent to this. */ /* So this is how we'll present our selves to the world */ if (m_exclusive_conn == null) { EndPoint ep = new IPEndPoint(IPAddress.Any, 0); if (!string.IsNullOrEmpty(m_local_endpoint)) { ep = new IPEndPoint(IPAddress.Parse(m_local_endpoint), 0); } m_exclusive_conn = new UdpClient((IPEndPoint)ep); m_exclusive_conn.DontFragment = m_dont_fragment; } } else { EndPoint ep = new IPEndPoint(IPAddress.Any, m_port); if (!string.IsNullOrEmpty(m_local_endpoint)) { ep = new IPEndPoint(IPAddress.Parse(m_local_endpoint), m_port); } m_exclusive_conn = new UdpClient(); m_exclusive_conn.ExclusiveAddressUse = true; m_exclusive_conn.Client.Bind((IPEndPoint)ep); m_exclusive_conn.DontFragment = m_dont_fragment; m_exclusive_conn.EnableBroadcast = true; } bvlc = new BVLC(this); }
private void Open() { if (!m_exclusive_port) { /* We need a shared broadcast "listen" port. This is the 0xBAC0 port */ /* This will enable us to have more than 1 client, on the same machine. Perhaps it's not that important though. */ /* We (might) only receive the broadcasts on this. Any unicasts to this might be eaten by another local client */ if (m_shared_conn == null) { m_shared_conn = new Net.Sockets.UdpClient(); m_shared_conn.ExclusiveAddressUse = false; m_shared_conn.Client.SetSocketOption(Net.Sockets.SocketOptionLevel.Socket, Net.Sockets.SocketOptionName.ReuseAddress, true); System.Net.EndPoint ep = new System.Net.IPEndPoint(System.Net.IPAddress.Any, m_port); if (!string.IsNullOrEmpty(m_local_endpoint)) ep = new System.Net.IPEndPoint(Net.IPAddress.Parse(m_local_endpoint), m_port); m_shared_conn.Client.Bind(ep); m_shared_conn.DontFragment = m_dont_fragment; } /* This is our own exclusive port. We'll receive everything sent to this. */ /* So this is how we'll present our selves to the world */ if (m_exclusive_conn == null) { System.Net.EndPoint ep = new Net.IPEndPoint(System.Net.IPAddress.Any, 0); if (!string.IsNullOrEmpty(m_local_endpoint)) ep = new Net.IPEndPoint(Net.IPAddress.Parse(m_local_endpoint), 0); m_exclusive_conn = new Net.Sockets.UdpClient((Net.IPEndPoint)ep); m_exclusive_conn.DontFragment = m_dont_fragment; } } else { System.Net.EndPoint ep = new Net.IPEndPoint(System.Net.IPAddress.Any, m_port); if (!string.IsNullOrEmpty(m_local_endpoint)) ep = new Net.IPEndPoint(Net.IPAddress.Parse(m_local_endpoint), m_port); m_exclusive_conn = new Net.Sockets.UdpClient(); m_exclusive_conn.ExclusiveAddressUse = true; m_exclusive_conn.Client.Bind((Net.IPEndPoint)ep); m_exclusive_conn.DontFragment = m_dont_fragment; } bvlc = new BVLC(this); }
private void Open() { if (!_exclusivePort) { /* We need a shared broadcast "listen" port. This is the 0xBAC0 port */ /* This will enable us to have more than 1 client, on the same machine. Perhaps it's not that important though. */ /* We (might) only recieve the broadcasts on this. Any unicasts to this might be eaten by another local client */ if (_sharedConn == null) { _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); _sharedConn.DontFragment = _dontFragment; Log.AddCustomEvent(LagoVista.Core.PlatformSupport.LogLevel.Message, "BacnetUdpProtocolTransport", $"Binded shared {ep} using UDP"); } /* This is our own exclusive port. We'll recieve everything sent to this. */ /* So this is how we'll present our selves to the world */ if (_exclusiveConn == null) { var ep = new IPEndPoint(IPAddress.Any, ExclusivePort); if (!string.IsNullOrEmpty(_localEndpoint)) { ep = new IPEndPoint(IPAddress.Parse(_localEndpoint), ExclusivePort); } _exclusiveConn = new UdpClient(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) { DontFragment = _dontFragment, EnableBroadcast = true }; DisableConnReset(_exclusiveConn); } } else { var ep = new IPEndPoint(IPAddress.Any, SharedPort); if (!string.IsNullOrEmpty(_localEndpoint)) { ep = new IPEndPoint(IPAddress.Parse(_localEndpoint), SharedPort); } _exclusiveConn = new UdpClient { ExclusiveAddressUse = true }; DisableConnReset(_exclusiveConn); _exclusiveConn.Client.Bind(ep); _exclusiveConn.DontFragment = _dontFragment; _exclusiveConn.EnableBroadcast = true; Log.AddCustomEvent(LagoVista.Core.PlatformSupport.LogLevel.Message, "BacnetUdpProtocolTransport", $"Binded exclusively to {ep} using UDP"); } Bvlc = new BVLC(this); }