[Mono-bugs] [Bug 45959][Cri] New - UDP Sockets: Multicast and Broadcast Datagrams are not received
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
Tue, 8 Jul 2003 01:50:34 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by giuseppe.greco@agamura.com.
http://bugzilla.ximian.com/show_bug.cgi?id=45959
--- shadow/45959 Tue Jul 8 01:50:34 2003
+++ shadow/45959.tmp.29751 Tue Jul 8 01:50:34 2003
@@ -0,0 +1,184 @@
+Bug#: 45959
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Red Hat 9.0
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Critical
+Component: System
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: giuseppe.greco@agamura.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Summary: UDP Sockets: Multicast and Broadcast Datagrams are not received
+
+UDP sockets don't receive Multicast and Broadcast
+datagrams - with Unicast datagrams there are no
+problems.
+
+Steps to reproduce the problem:
+1. Write a sender like this:
+
+using System;
+using System.Net;
+using System.Net.Sockets;
+using System.Threading;
+
+public class MySender
+{
+ private static bool sent = false;
+
+ public static void Main()
+ {
+ byte[] data = new byte[10];
+ for (byte i = 0; i < 10; i++) {
+ data[i] = (byte) i;
+ }
+
+ IPEndPoint ipEndPoint=
+ new IPEndPoint(IPAddress.Parse("224.100.0.1"), 9000);
+
+ Socket socket = new Socket(
+ AddressFamily.InterNetwork,
+ SocketType.Dgram,
+ ProtocolType.Udp);
+
+ socket.SetSocketOption(
+ SocketOptionLevel.IP,
+ SocketOptionName.AddMembership,
+ new MulticastOption(ipEndPoint.Address));
+
+ //
+ // uncomment this to test broadcast
+ //
+ // socket.SetSocketOption(
+ // SocketOptionLevel.Socket,
+ // SocketOptionName.Broadcast,
+ // 1);
+
+ EndPoint endPoint = (EndPoint) ipEndPoint;
+ socket.BeginSendTo(
+ data,
+ 0,
+ data.Length,
+ SocketFlags.None,
+ endPoint,
+ new AsyncCallback(new MySender().AsyncSend),
+ socket);
+
+ while (!sent) {
+ Thread.Sleep(10);
+ }
+ }
+
+ void AsyncSend(IAsyncResult ar)
+ {
+ Socket socket = (Socket) ar.AsyncState;
+ socket.EndSendTo(ar);
+ sent = true;
+ }
+}
+
+
+2. Write a receiver like this:
+
+using System;
+using System.Net;
+using System.Net.Sockets;
+using System.Threading;
+
+public class MyReceiver
+{
+ private byte[] data;
+ private EndPoint endPoint;
+
+ public static void Main()
+ {
+ MyReceiver myReceiver = new MyReceiver();
+ myReceiver.Send();
+ }
+
+ private void Send()
+ {
+ IPEndPoint ipEndPoint=
+ new IPEndPoint(IPAddress.Parse("224.100.0.1"), 9000);
+
+ Socket socket = new Socket(
+ AddressFamily.InterNetwork,
+ SocketType.Dgram,
+ ProtocolType.Udp);
+
+ socket.Bind(new IPEndPoint(IPAddress.Any, 9000));
+
+ socket.SetSocketOption(
+ SocketOptionLevel.IP,
+ SocketOptionName.AddMembership,
+ new MulticastOption(ipEndPoint.Address));
+
+ endPoint = (EndPoint) ipEndPoint;
+
+ while (true) {
+ if (socket.Poll(250000, SelectMode.SelectRead)) {
+ data = new byte[socket.Available];
+ socket.BeginReceiveFrom(
+ data,
+ 0,
+ data.Length,
+ SocketFlags.None,
+ ref endPoint,
+ new AsyncCallback(AsyncReceive),
+ socket);
+ }
+ }
+ }
+
+ private void AsyncReceive(IAsyncResult ar)
+ {
+ Socket socket = (Socket) ar.AsyncState;
+
+ if (0 < socket.EndReceiveFrom(ar, ref endPoint)) {
+ foreach (byte b in data) {
+ Console.Write(b.ToString("X"));
+ }
+ Console.WriteLine("");
+ }
+ }
+}
+
+
+3. Compile the two applications:
+
+ mcs -t:exe -out:receiver.exe receiver.cs
+ mcs -t:exe -out:sender.exe sender.cs
+
+
+4. Start the receiver:
+
+ mono ./receiver.exe
+
+
+5. Start the sender:
+
+ mono ./sender.exe
+
+
+Actual Results:
+Multicast and Broadcast datagrams are
+not received. Unicast datagrams are
+received.
+
+
+Expected Results:
+Multicast and Broadcast datagrams should
+be received.
+
+
+How often does this happen?
+Always.
+
+
+Additional Information:
+The code above works fine with .NET on Windows.