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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:42:36+00:00 2026-06-16T08:42:36+00:00

I came across this code snippet online. However, I cannot understand how the while(true)

  • 0

I came across this code snippet online. However, I cannot understand how the while(true) blocking takes place in this code:

private void ListenForClients()
{
  this.tcpListener.Start();

  while (true)
  {
    //blocks until a client has connected to the server
    TcpClient client = this.tcpListener.AcceptTcpClient();

    //create a thread to handle communication
    //with connected client
    Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm));
    clientThread.Start(client);
  }
}

Can anyone explain it to me? I know of using while(true) + breaking condition, but this thing is beyond me.

  • 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-06-16T08:42:38+00:00Added an answer on June 16, 2026 at 8:42 am

    It’s not the while(true) that does the blocking, it’s the AcceptTcpClient(). This is what happens:

    1. tcpListener is started.
    2. The loop is started (since true is always true)
    3. this.tcpListener.AcceptTcpClient() is executed and the thread stops, because AcceptTcpClient is a blocking method.
    4. If a connection request is made the block goes away and a TcpClient is returned as the variable client.
    5. A new thread is created for client
    6. The loop goes back again to AcceptTcpClient and stops there until a new connection is made.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in the book i'm learning from i came across this code snippit: while (i
While looking through some old code I came across this gem: MyObject o =
While reading Play! Framework documentation, I came across this snippet: def index = Action
In the Pragmatic Core Data book, I came across this code snippet for an
I came across something peculiar today. Take a look at this code snippet: List
Im a newbie to python , and I came across this particular code snippet
I came across a jQuery snippet like this: selector.eventHandler(...some code...).eventHandler(...some code...); What does it
I came across this code and need to understand what it is doing. It
I came across this code snippet 1 int return_printChar1() { // code // oops!
I came across this code while I was browsing for html5 canvas examples. I

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.