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

  • Home
  • SEARCH
  • 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 6605653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:18:34+00:00 2026-05-25T19:18:34+00:00

I have a program whereby Data is being sent from one computer to another

  • 0

I have a program whereby Data is being sent from one computer to another via UDP. The problem is that data may not always be sent by the sending program and I want my receiving program’s receive functionality to be enabled ONLY when something is being sent to a specified port (5000 in this case), otherwise when the user tries to receive data on the port using UdpClient the program crashes. For example:

    private const int listenPort = 5000;//receiving port
    UdpClient listener = new UdpClient(listenPort);//udclient instance
    IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
    public string received_data;
    public byte[] receive_byte_array;

    private void receiveButton_Click(object sender, RoutedEventArgs e)
    {
        receive_byte_array = listener.Receive(ref groupEP);
        received_data = Encoding.ASCII.GetString(receive_byte_array, 0, receive_byte_array.Length);
        textBox1.Text = received_data.ToString();

    }

My problem here is when there is no data being sent and the User clicks receiveButton on the main window my whole program crashes. To be specific the problem is here:
receive_byte_array = listener.Receive(ref groupEP);

I’ve tried to fix the problem by putting the above line of code in a try catch statement but even then the program crashes! It seems merely trying to receive data on the IPEndpoint port when there is none raises hell.

Any ideas as to how I can first check if data is being sent to the port and only then allow the user to receive data? 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-25T19:18:34+00:00Added an answer on May 25, 2026 at 7:18 pm

    based on your comment I’d say the program is freezing because it is waiting for data to receive. your user interface freezes because you’ve started listening for data synchronously from the UI thread and it is now preoccupied with listening for data and not repainting or processing input. to fix this put the listening bit in a separate thread or use the async BeginReceive method to receive the data.

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

Sidebar

Related Questions

I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that runs osql.exe from microsoft sql server tools directory and
I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that spits out an Excel workbook in Excel 2003 XML
I have a program that monitors debug messages and I have tried using a
I have a program that will calculate the minimal area taken by fitting rectangles
I have a program that accepts a Cmd command as a command argument. Basically
I have a program that reads a raw list of in-game entities, and I
I have a program written in VB that has DataDynamics ActiveReports as well as

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.