Bind of Port RRS feed

  • Question

  • Asalam Alaikum (Greetings)!

    I am using ddns for getting IP like and it returns IP address of the host. My objective is to receive data from through UDP, because TCP is not working. It shows error unable to start server on, where as it shows result on local IPs like 192.168.*.*. I search on the web and conclude that i need to make UDP listener, but it won't work. UDP listener is not working ddns. I might be doing something wrong, kindly help.


    UdpClient udpClient = new UdpClient(4337);
    udpClient.EnableBroadcast = true;

    t = true;

                    IPEndPoint hostIP = new IPEndPoint(IPAddress.Parse(""), 4337);
                    byte[] bytes = udpClient.Receive(ref hostIP);
                    t = false;


    Kindly help,

    Muhammad Naveed Haroon

    Tuesday, July 23, 2019 12:27 PM

All replies

  • Unless your PC is directly connected to the internet, which for security reasons is almost NEVER done these, you will never see that external IP address.  It's all handled by your router/gateway.  Your application should bind to the IP address assigned to your network card, and your router (assuming you have configured it to do so) will forward packets from the outside world to your PC.

    You can use this code to get the IP address of your PC:

    IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 4337);

    TCP works just fine for this, of course.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Tuesday, July 23, 2019 5:25 PM
  • Hi MuhammadNH, 

    Thank you for posting here.

    For your question, I make a test and use UdpClient to create a UDP listener.

    You can refer the following code:

            private static readonly IPAddress GroupAddress = IPAddress.Parse("IPAddress(IPv6)");
            private const int GroupPort = 4337;
            private static void StartListener()
                bool done = false;
                UdpClient listener = new UdpClient();
                IPEndPoint groupEP = new IPEndPoint(GroupAddress, GroupPort);
                    while (!done)
                        byte[] bytes = listener.Receive(ref groupEP);
                        Console.WriteLine($"Received broadcast from {groupEP.ToString()} :\n {Encoding.ASCII.GetString(bytes, 0, bytes.Length)}\n");
                catch (Exception e)

    Hope it can help you.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, July 24, 2019 7:37 AM