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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:32:01+00:00 2026-06-16T09:32:01+00:00

I have written a TCP server application in C code that can handle multiple

  • 0

I have written a TCP server application in C code that can handle multiple clients connections at the same time. When the server receive data from one client, all the clients should receive it.
I’ve used select() in order to create the connection between server and multiple clients but i don’t know how to do that all the clients receive the same data at the same time and each of them be able to send data to the server.

read_option(fd) is my function used in the application

while(1)
{
    select (nfds+1, &readfds, NULL, NULL, &tv);
    if (FD_ISSET (sd, &readfds))
    {
        len = sizeof (from);
        bzero (&from, sizeof (from));
        client = accept (sd, (struct sockaddr *) &from, &len);
        if (client < 0)
        {
            continue;
        }
        if (nfds < client) 
            nfds = client;
        FD_SET (client, &actfds);
        fflush (stdout);
    }
    for (fd = 0; fd <= nfds; fd++)  
    {
        if (fd != sd && FD_ISSET (fd, &readfds))
        {
            if (read_option(fd))
            {
                fflush (stdout);
                close (fd);
                FD_CLR (fd, &actfds);
            }
        }
    }
  • 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-16T09:32:02+00:00Added an answer on June 16, 2026 at 9:32 am

    If you want to send and receive from multiple clients at the same time – at least for the receive side – you will need to use threads, as there is no way all your clients can send data to your server at once, and each client’s packets will need to be handled separately. (I’m assuming that the data received in “read_option” is more than a few bytes and takes more than a few microseconds to process – if that assumption is false, then you may be able to do what you are currently doing – but I’m pretty sure it’s EASIER to solve it using threads). Obviously, also, if you have sufficient number of clients, you may still not have enough CPU or network bandwidth to process all packets within a set amount of time.

    It may be possible to use multicast to send to all clients simultaneously – but you can’t guarantee that all clients receive the data simultaneously, – certainly not if we are talking computer time simultaneously. If the clients are on a the same network as the server, and if we are talking human reaction time (0.05-0.1s), then perhaps you can achieve that. If the machines are distributed over the entire internet, you should be happy to achieve 0.1-0.5s – and quite possibly worse.

    So, given the comments:

    Because you are doing send() and receive() in read_option(), your read_option will block at that point, so any other client will not be processed.

    You will essentially need to start a thread for each client, using pthread_create(). You can then “chat” between the server and each of the clients independently of each other. I expect you’ll ALSO need to have some sort of synchronization between each thread, so that they don’t run ahead of each other, or some such. Since I don’t know what game you are playing, I’m not sure what the “rules of play” should be, and can’t really comment on that – in fact, I think that’s a great subject for another question, rather than in this question [otherwise, I’ll fear it never ends!]

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

Sidebar

Related Questions

I currently have a TCP server application written in .Net that receives and submits
I have a TCP/IP server written in C# .net which can have 10,000 connections
I have written a TCP server application in c#. Application listens for inbound connections
I have written a C# server which listens for Tcp connections. A client can
i have a multi-threaded TCP server that is written in C#. Clients are accepted
I have a TCP server app that is written in C#. I accept TCP
I have written a TCP server implementation using which I created an application which
I have two utilities written in C++, TCP/IP server and client that I have
I have 2 machines running a simple C TCP server that I have written
I have a client/server application written in delphiXe2 using Indy TIdTCPServer and TIdTCPClient that

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.