Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am trying to listen on a specific port on Windows 7 with IPV6 enabled. The client from Windows XP is broadcasting a message to all computers on LAN(using IP 255.255.255.255 which is not related to specific computer and used for broadcasting to all PC's in LAN). All computers can listen and receive this broadcast message if they are on WinXP. But if listener is on Windows 7 it do not receive this broadcast message using IPV6. If IPV6 is changed to IPV4 from Network And Sharing Center->Local Area Connection then, the message is received successfully. Please refer attached code that we are using for receiver and listener written in C#.NET.

//ConcoleApplication1
//Program.cs- Work as Listnear on port 36502 and listen
// from all IP's on LAN
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
public class UDPListener
{
    private const int listenPort = 36502;
    private static void StartListener()
    {
        bool done = false;
        UdpClient listener = new UdpClient(listenPort);
        listener.Client.EnableBroadcast = true;
        listener.EnableBroadcast = true;
        IPEndPoint groupEP = new IPEndPoint(IPAddress.IPv6Any, listenPort);
        try
        {
            while (!done)
            {
                Console.WriteLine("Waiting for broadcast");
                byte[] bytes = listener.Receive(ref groupEP);
                Console.WriteLine("Received broadcast from {0} :\n {1}\n",
                    groupEP.ToString(),
                    Encoding.ASCII.GetString(bytes, 0, bytes.Length));
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
        finally
        {
            listener.Close();
        }
    }
    public static int Main()
    {
        StartListener();
        return 0;
    }
}
Posted
Updated 14-Oct-10 4:53am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900