Only one use of each socket address (proto/ip/port)
<p>Good day all</p>
<p><strong>Info:</strong></p>
<p>Topic: Multicast</p>
<p>First off, I have found the solution but I do not understand why this is the solution.</p>
<p>**Scope : ** (removing any cluttering/unnecessary code)</p>
<pre><code>new_socket()
{
    //SND_LOCAL_IP = 10.0.0.30 - local network adapter's IP
    //SND_MCAST_PORT = 80 port used to broadcast Multicast Packets 

    //_SND_LOCAL_EP = new IPEndPoint(SND_LOCAL_IP, SND_MCAST_PORT);  &lt;problem&gt;                                       
    _SND_LOCAL_EP = new IPEndPoint(SND_LOCAL_IP, 0);                 &lt;fixed&gt;    
}

init_socket()
{
    _SND_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    _SND_Socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(_SND_MCAST_IP, _SND_LOCAL_IP));
    _SND_Socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.ReuseAddress, true);
    _SND_Socket.ExclusiveAddressUse = false;
    _SND_Socket.Bind(_SND_LOCAL_EP);      &lt;&lt;&lt; ====== PROBLEM LINE=====
}
</code></pre>
<p><strong>The problem:</strong></p>
<p>My listener runs on a Thread seperately, on a form_load event, thus it initializes in the same way as my SND_Socket does, however changing the <code>SND_Socket.Bind()</code> port to 0 allows me to recieve these Multicast packets.</p>
<p>As by the <a href="https://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.exclusiveaddressuse(v=vs.110).aspx" rel="nofollow noreferrer">def MSDN</a>, adding the ExclusiveAddress should not alleviate this problem (since the recieve and send sockets are initialized in the same way).</p>
<blockquote>
<p>true if the Socket allows only one socket to bind to a specific port; otherwise, false. The default is true for Windows Server 2003 and Windows XP Service Pack 2, and false for all other versions.</p>
</blockquote>
<p>and further on, in Remarks this is confirmed:</p>
<blockquote>
<p>If ExclusiveAddressUse is false, multiple sockets can use the Bind method to bind to a specific port; however only one of the sockets can perform operations on the network traffic sent to the port. If more than one socket attempts to use the Bind(EndPoint) method to bind to a particular port, then the one with the more specific IP address will handle the network traffic sent to that port.</p>
<p>If ExclusiveAddressUse is true, the first use of the Bind method to attempt to bind to a particular port, regardless of Internet Protocol (IP) address, will succeed; all subsequent uses of the Bind method to attempt to bind to that port will fail until the original bound socket is destroyed.</p>
<p>This property must be set before Bind is called; otherwise an InvalidOperationException will be thrown.</p>
</blockquote>
<p><strong>Why</strong> does the</p>
<blockquote>
<p>Socket.ExclusiveAddress = false</p>
</blockquote>
<p>not allow the SND_Socket to listen on this IP and port as &quot;Listener_Socket&quot;, furthermore why does setting port to 0 in the <code>RCV_Socket.Bind()</code> solve this problem?</p>