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 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 recieve 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; m_exclusive_conn.EnableBroadcast = true;
}
bvlc = new BVLC(this);
}