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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:48:26+00:00 2026-05-17T17:48:26+00:00

I have written C code for a TCP server to listen to one client

  • 0

I have written C code for a TCP server to listen to one client at a time.. but I’m having difficulty figuring out how I can get the server to listen to multiple clients at one time.

Does any one know of a good tutorial or example explaining this?

Thanks!

  • 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-17T17:48:27+00:00Added an answer on May 17, 2026 at 5:48 pm

    There are a number of ways to achieve this, some of which are:

    • use select to basically wait on a group of file descriptors until one of them is ready for reading or writing.
    • use threading, such as pthreads, to hand off individual sessions to separate threads within the one process.
    • use fork to replicate the process for handling a session, so that the forked process handles that session and the original goes back to waiting for more connections.

    Of these, I prefer the middle one. Forking a process is a sometimes-expensive operation in that the data normally has to be copied if either process attempts to change it.

    The select option means that your code has to manage multiple sessions and that can sometimes get messy.

    With threading, you can separate relatively easily the sessions from each other, without incurring the cost of process duplication. Of course, threading has its own pitfalls if you’re not careful but I consider it a preferable option once you understand the potential problem areas.

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

Sidebar

Related Questions

I have written a simple TCP client and server. The problem lies with the
I have two utilities written in C++, TCP/IP server and client that I have
I have existing chat server code written in C/C++ that communicates over TCP/IP with
I have written code for server and client sockets. I have used threads using
I have written some code for displaying a drop down list, but the code
In sockets I have written the client server program. First I tried to send
I have created a server/client application. Both of them are written in C#. It
I want to write (TCP) Server Client program. Client code should be in Objetive-C.
I have a server written in Java. Its a simple one that echoes HELLO
I have written a TCP server application in c#. Application listens for inbound connections

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.