Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6140575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:08:07+00:00 2026-05-23T18:08:07+00:00

I am trying to test UDP communications on a LAN. I have a small

  • 0

I am trying to test UDP communications on a LAN. I have a small piece of code to and I have tried to run it in 2 computers (one should wait to receive and the other one should send). The strange thing is that computer A sends and B receives properly but if I try A to receive and B to send it does not work. Do you know why could it be?

public void SendBroadcast(int port, string message)
    {
        UdpClient client = new UdpClient();
        byte[] packet = Encoding.ASCII.GetBytes(message);

        try
        {
            client.Send(packet, packet.Length, IPAddress.Broadcast.ToString(), port);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

public void Receive(int port)
    {
        UdpClient client = null;

        try
        {
            client = new UdpClient(port);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        IPEndPoint server = new IPEndPoint(IPAddress.Any, 0);


        while (true) 
        {
            try
            {
                byte[] packet = client.Receive(ref server);
                Console.WriteLine("{0}, {1}", server, Encoding.ASCII.GetString(packet));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }

And the calls:

  SendBroadcast(444, "hello"); Receive(444);

If I run 2 instances of the program on the same computer it works properly but creates 3 packages per call.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:08:08+00:00Added an answer on May 23, 2026 at 6:08 pm

    Well, if the same code works on one and not the other, it’s your environment. Check your firewall settings, make sure it’s not preventing the broadcast on the sender or preventing receipt on the receiver. Wireshark (or even Windows’ netmon) should be helpful here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just trying to test for equality in this piece of code, but getting a
I'm trying to test some TPL dataflow code and run into what looks like
I'm trying to test if the xml file have the tag <group> var xmlhttp
I'm trying to test my Session Beans with JUnit, but I can't. I've tried
I am trying to test some DAOs. I have Entity (and table) named Nomination
/home/bar/foo/test.py: I am trying test.py to print /home/bar/foo irrespective of from where I run
I'm trying to test a php file from a C program(...) Basically I have
I am trying to test a proof of concept that I can run a
I am trying to implement a simple UDP client and server. Server should receive
I'm trying to test jasperreport and wrote Java code but it giving me error:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.