Last active
August 29, 2015 14:08
-
-
Save justincc/c431165a6d7194169328 to your computer and use it in GitHub Desktop.
Example program to bind two sockets to same UDP port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
using System.Net.Sockets; | |
public class UdpSamePort | |
{ | |
public static void Main(string[] args) | |
{ | |
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9000); | |
Socket udpSocket1 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); | |
udpSocket1.Bind(ipep); | |
Socket udpSocket2 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); | |
// Uncomment this line causes the udpSocket2 bind to throw an exception complaining that the address is already in use. | |
//udpSocket2.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, false); | |
udpSocket2.Bind(ipep); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This fails on Windows with the expected "Only one usage of each socket address is normally permitted" message. At least on Mono 3.2.8 this raises no error.