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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:52:22+00:00 2026-05-23T14:52:22+00:00

I have a server and a client application, here’s how it’s currently implemented: The

  • 0

I have a server and a client application, here’s how it’s currently implemented: The server has a loop, in its own thread, that listens for new connections through a TcpListener. If someone connects, it passes the TcpClient to a loop that listens to that TcpClient specifically, and handles all interaction with that user through NetworkStream.

On the client, I have a TcpClient that connects to the server. It’s my understanding that I need to branch it to a different thread, since any IO will put it in to blocking mode, and I can’t let it stop the main thread.

So far, am I understanding it correctly? Is there an easier way to asure asynchronous communication without stopping the main thread for either program?

Either way, for my main question: How do I make sure all of these threads and sockets are properly disposed of? If a program exits while it’s still in blocking mode, it seems to freeze. So how do I abort all IO on the socket and tell the infinite loop in the child threads that we’re done?

This is also a Unity3d project by the way, in case that changes anything.

  • 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-23T14:52:23+00:00Added an answer on May 23, 2026 at 2:52 pm

    Handing off each new connection to its own thread could limit your scalability down the line. Also there’s no reason to require thread handoff for I/O in the client.

    You can resolve both issues by using async I/O. BeginConnect/EndConnect on the client, BeginRead/EndRead, BeginWrite/EndWrite on the server side for reads and writes.

    Then everything can be event-driven without any need for new threads of your own. Connect completion triggers first async read, then each read completion posts a new async read call on that socket – writes are always deterministic from your POV anyway.

    Closing your sockets will results in pending reads/writes exiting out with an error, and then you should be able to exit the process cleanly. Be careful that you implement appropriate locking (likely lock() will be all you need) to ensure sockets are not used anywhere after they have been closed.

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

Sidebar

Related Questions

I currently have a client-server application that involves a Silverlight client and a .NET
i have a server - client application that runs on java 1.3; i want
I have a client/server application that communicates with .Net remoting. I need my clients
I have a client server application that sends XML over TCP/IP from client to
I have a client-server application that uses .net remoting. The clients are in a
Background: We have a client/server application that uses a persistent connection to the server.
I've got a small client/server test application where I have a Flex app that
I have got a Client/Server Application that using Asynchronous Socket.My problem is i cant
I have a server-client application that is using a datagram socket to exchange messages.
I have a client/server application written in C#/.NET 3.5 that I want to do

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.