CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: UDP Bug

  1. #1
    Join Date
    Jun 2010
    Posts
    5

    UDP Bug

    I am attempting to listen to UDP Multicast messages on 239.255.255.250 port 1900 but am seeing very strange behavior.

    When I use the code below it will work but only see one set of network UDP traffic. Either "127.0.0.1" i.e. loopback traffic or "192.168.1.111" - Local IP to router traffic.

    So for example I start my program and it can only see loopback traffic and nothing else.

    I restart the program and now it can only see the "192.168.1.111" traffic and no loopback traffic.

    It seems to randomly choose which set of traffic it will see and I cannot control it.

    How the heck do I get the UDP Client to see either all nework traffic UDP messages or make it always get real network traffic and not just loopback consistently?

    The entire sample code is provided below:

    Code:
    private void TryUDP()
    {
       UdpClient client = new UdpClient();
       client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
       IPEndPoint EndPoint = new IPEndPoint(IPAddress.Any, 1900);
       client.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"));
       client.Client.Bind(EndPoint);
    
       while (true)
       {
        byte[] data = client.Receive(ref EndPoint);
        string stringData = Encoding.ASCII.GetString(data, 0, data.Length);
    
        Console.WriteLine("From: " + EndPoint.ToString() + "\n" + stringData);
       }
       client.Close();
    }
    Last edited by metalideath; September 12th, 2010 at 11:52 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured