locked
UDP Multicast... RRS feed

  • Question

  • Hey,

    I am trying to receive UDP Multicast Msg's from 239:255:255:250:1900. But it doesnt work Crying I've tried these lines of code under Windows XP and it works fine. But under my Win CE 6.0 it won't work.


    Code Block
    int intRecBytes;
                byte[] b = new byte[1024];

                intRecBytes = 0;
                Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                try
                {
                    IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 1900);
                    s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);

                    s.Bind(ipep);
                    IPAddress ip = IPAddress.Parse("239.255.255.250");

                    s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any));

                    while (true)
                    {

                        Console.WriteLine("Waiting for data..");
                        int count = s.Receive(b);
                      //  intRecBytes = s.ReceiveFrom(data, ref Remote);
                        string str = System.Text.Encoding.ASCII.GetString(b, 0, b.Length);
                        Console.WriteLine("RX: " + str.Trim());
                    }
                    s.Close();
                }
                catch (Exception esv)
                {
                    Console.WriteLine(esv.ToString());
                }

    Does anybody know why? Thanx for the help in advance...

    cheers, pete
    Thursday, November 22, 2007 9:32 AM

Answers

  • Hi Pete,

    I am afraid your problem may be network problem. Please check whether your device can connect the Multicast Group IP. You can try to  ping the ip to check. There is a good tool which can run ping command,

     

    You can click the link below to download:

    http://www.pocketpcfreeware.com/fr/index.php?soft=1612

     

    Best regards,

    Guang-Ming Bian - MSFT

     

     

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Wednesday, November 28, 2007 2:30 AM

All replies

  • Hi pete,

    What error do you get?  Can you provide more code including client and server side code?

     

    Thanks,

    Guang-Ming Bian - MSFT

    Monday, November 26, 2007 6:42 AM
  • Hi,

    it is just an example to receive data. In fact, I dont have more code. I just want to receive UDP Multicast Messages.

    The error I get is nothing, because my "Client" is not receiving any packets...

    Cheers,

    pete
    Monday, November 26, 2007 6:50 AM
  • Hi pete,

    In a Multicast Group, one point send data, other points of the group can receive the data. This is the defination of Multicast, So you must have a point to send data. Then use your code to receive the data:

    How to send data:

    Code Block

    void send(string mcastGroup, string port, string ttl, string rep)

                    {

                            IPAddress ip;

                            try

                            {

                                    ip=IPAddress.Parse(mcastGroup);

                                   

                                    Socket s=new Socket(AddressFamily.InterNetwork,

                                                                    SocketType.Dgram, ProtocolType.Udp);

                                   

                                    s.SetSocketOption(SocketOptionLevel.IP,

                                            SocketOptionName.AddMembership, new MulticastOption(ip));

     

                                    s.SetSocketOption(SocketOptionLevel.IP,

                                            SocketOptionName.MulticastTimeToLive, int.Parse(ttl));

                           

                                    byte[] b=new byte[10];

                                    for(int x=0;x<b.Length;x++) b[x]=(byte)(x+65);

     

                                    IPEndPoint ipep=new IPEndPoint(IPAddress.Parse(mcastGroup),int.Parse(port));

                                   

                                    Console.WriteLine("Connecting...");

     

                                    s.Connect(ipep);

                                    s.Send(b,b.Length,SocketFlags.None);

                    

                                    Console.WriteLine("Closing Connection...");

                                    s.Close();

                            }

                            catch(System.Exception e) { Console.Error.WriteLine(e.Message); }

                    }

     

     

     

    There is a step by step document in codeproject of multicast:

    http://www.codeproject.com/cs/internet/multicast.asp

     

    Best regards,

    Guang-Ming Bian - MSFT

    Tuesday, November 27, 2007 3:20 AM
  • Hi,


    this works fine on a normal PC. But have u ever tried to run these lines of code on a mobile device under Windows CE 5.0/ 6.0?! It doesn't work!

    Regards,

    Pete
    Tuesday, November 27, 2007 7:53 AM
  • Hi Pete,

    I am afraid your problem may be network problem. Please check whether your device can connect the Multicast Group IP. You can try to  ping the ip to check. There is a good tool which can run ping command,

     

    You can click the link below to download:

    http://www.pocketpcfreeware.com/fr/index.php?soft=1612

     

    Best regards,

    Guang-Ming Bian - MSFT

     

     

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Wednesday, November 28, 2007 2:30 AM
  • Hey,

    I've tried several Network configurations... And suprise: It doesnt work as well. The network is fine, because I can use the IE to go on www.google.com or other websites.

    I am totaly demotivated about the multicast problem. Has somebody of you tried to receive UDP Multicsat? It seems to be a Bug or an unknown Feature, right? :-) At least I am not loosing my ironic thiniking Smile

    Cheers,

    Pete
    Friday, November 30, 2007 1:08 PM
  • In case anyone is monitoring this, I think there's still a bug in the network stack of CE versions < 6 (at least), that prevents you from joining multicast groups that have certain address formats.  Try, instead of your group, something like 254.0.0.103 as the group.

     

    Paul T.

     

    Thursday, June 26, 2008 8:36 PM
  • Hi,

    As you, I had a similar problem.
    I've tested the DPWS application(service) on a Windows CE 6.0 R2.
    The application could send a multicast message (e.g. HELLO) but couldn't receive a multicast message (e.g. Resolve).
    Then, the application didn't respond a ResolveMatch message.

    Best regards.
    Pusik.

    Wednesday, May 20, 2009 11:38 AM
  • In the network stack of CE version 6.0 R2, does the multicast problem solved ?
    Though my system was windows ce 6.0 R2 ,updated by March 2009, I've met the same problem.
    Wednesday, May 20, 2009 11:41 AM
  • As my analysis, my windows ce 6.0 r2 system couldn't join the multicast group.
    Though the system sent "IGMP V3 Membership report / Join group 239.255.255.250 for any sources", it couldn't receive any response.
    I thought that it couldn't receive a multicast message like a "Resolve" because it couldn't join a group.
    However, it is interesting that the same application on a Vista didn't send a IGMP's Join message and operateed correctly.
    Best regards.
    Pusik.

    Wednesday, May 20, 2009 11:49 AM