[Mono-bugs] [Bug 643475] Socket.ExclusiveAddressUse not working with UDP
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Oct 4 07:14:06 EDT 2010
https://bugzilla.novell.com/show_bug.cgi?id=643475
https://bugzilla.novell.com/show_bug.cgi?id=643475#c1
--- Comment #1 from Antonio Anzivino <djechelon at fastwebnet.it> 2010-10-04 11:14:05 UTC ---
We just submitted a workaround into our code repository
http://logbus-ng.svn.sourceforge.net/viewvc/logbus-ng?view=revision&revision=396
Everyone experiencing the same problem could use our approach: scan the list of
running UDP listeners via IPGlobalProperties
For each port in the range of known ports, try to find it in the active sockets
list ;-)
#if MONO
IPEndPoint[] eps =
IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners();
#endif
for (int i = START_PORT; i <= END_PORT; i++)
{
#if MONO
//Workaround to Mono bug 64375
bool found = false;
for (int c = 0; c < eps.Length; c++)
{
if (eps[c].Port == i &&
(eps[c].Address.Equals(IPAddress.Any) || eps[c].Address.Equals(localIp)))
{
found = true;
break;
}
}
if (!found)
{
Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
socket.Bind(new IPEndPoint(localIp, i));
_client = new UdpClient { Client = socket };
break;
}
#else
try
{
Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp) { ExclusiveAddressUse = true };
socket.Bind(new IPEndPoint(localIp, i));
_client = new UdpClient { Client = socket };
break;
}
catch (SocketException)
{ }
#endif
}
Adapt this code to your needs and voilà
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list