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 7698533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:15:51+00:00 2026-05-31T22:15:51+00:00

Please refer my previous question for code sample Sockets: sometimes (rarely) packets are lost

  • 0

Please refer my previous question for code sample Sockets: sometimes (rarely) packets are lost during receiving

I need to receive data always from UDP multicast socket. This is one-way comminication I just need to listen for new data and process it asap.

Should I use while(true)? I don’t like while(true) because in my opinion this produce a lot of extra-work for processor. Probably c# offers other call-back techniques or something?

  • 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-31T22:15:53+00:00Added an answer on May 31, 2026 at 10:15 pm

    2 to 6 sockets (comments) is probably in the interesting place where either blocking or async IO will work fine, since you aren’t swamping the machine with threads. With 2000 packets per second, it sounds like there is plenty to keep the threads busy. You don’t need to worry about while(true) from a performance perspective, since the Receive method will block until data is available, so it is never doing a hot-loop of doing nothing. However! Personally, from a cosmetic perspective, I agree while(true) is an unnecessary blot, so if you are using the blocking approach, maybe consider:

    int bytesRead;
    while((bytesRead = socket.Receive(buffer)) > 0) {
        // process bytesRead from buffer
    }
    

    which will exit cleanly when the socket is closed.

    You can also do this with either the BeginReceive and Socket.ReceiveAsync methods, which doesn’t use a blocking call, but instead uses either an event or callback. These are particularly useful when handling lots of connections.

    Personally, what I tend to do is use Socket.Available; if this is positive, then there is data buffered and ready to consume, so a simple Receive can be used to fetch that data promptly and without a context-switch. If it is zero, then no data is currently available, so an async call may be more appropriate. This balances context-switches with direct calls. Note that the ReceiveAsync approach has this built in too, via the return value from ReceiveAsync (which is true if the operation is incomplete, and a callback will be invoked later – and false if the operation is already complete, and no callback will be invoked).

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

Sidebar

Related Questions

Please refer to my previous question here: Link Here Will this project type be
I have question please refer the following code to understand the question. (I removed
Please refer my previous post here . I did changes accordingly but getting error.
Please refer to this background question. After constructing this COUNT, how would I then
Please refer to http://jsfiddle.net/7FfMd/6/ run the code, then select E from the drop down,
Please refer to the below code Specialized function in non specialized Template class Is
Please refer code below i m learning jquery and i want to display tag
Please refer to my code below. When optimization in IAR MSP430 compiler is set
Please refer to the following code: Filename: myclass.h @interface myclass:NSObject ... @end @interface NSObject(CategoryName)
Please refer to code. <%= form_tag(:action => create_user, :method => post) do%> <p><label for=first_name>First

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.