none
Bind of Port RRS feed

  • Question

  • Asalam Alaikum (Greetings)!

    I am using ddns for getting IP like autoclone.ddns.net 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 ddns.net, 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.

    <CODE>

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

    t = true;

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

    </CODE>

    Kindly help,

    Regards,
    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);
                try
                {
                    //IPv6
                    listener.JoinMulticastGroup(GroupAddress);
                    listener.Connect(groupEP);
                    while (!done)
                    {
                        byte[] bytes = listener.Receive(ref groupEP);
                        Console.WriteLine($"Received broadcast from {groupEP.ToString()} :\n {Encoding.ASCII.GetString(bytes, 0, bytes.Length)}\n");
                    }
                    listener.Close();
                }
                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 MSDNFSF@microsoft.com.

    Wednesday, July 24, 2019 7:37 AM
    Moderator