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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:07:17+00:00 2026-05-27T18:07:17+00:00

The situation : I am creating a server daemon in c that accepts numerous

  • 0

The situation: I am creating a server daemon in c that accepts numerous simultaneous connections, and the clients will be sending data to the server. I currently have each client connection being spawned into a new thread.

The problem: if a client sends numerous lines of content very quickly (eg, 10 lines of data in less than a second), the server will see the first two lines, but not the rest.

The question: How can I “queue” the data coming in from the clients (the recv command in c)? Is this something that select or poll would be needed for? Basically, I want to make sure any client can send large amounts of data very quickly without having to worry about any content being dropped. How can this be achieved?

Sample Code: (note: the below code has obviously been heavily modified, esp. by removing error checking. I tried to modify my code so as to make the problem/solution clear without getting bogged down in semantics of irrelevant parts. Please don’t get caught up with any non-standard or missing elements here)

//this function handles the threads
void *ThreadedFunction(void *arg) {
    // do some stuff, like: pull vars out of mystruct
    int nbytes;
    char buf[256];
    while(1) {
        if((nbytes=recv(conid, buf, sizeof buf, 0)) <= 0) {
            //handle break in connection
        } else {
            //for this example, just print out data from client to make my point
            buf[nbytes] = 0;
            printf("%s\n",buf);
        }
    }
}

//main just sets up the connections and creates threads
int main(int argc. char *argv[])
{
    // bind(), listen(), etc... blah blah blah

    while(1) {
        conid = accept(...); //get a connection
        // ... build mystruct to pass vars to threaded function ...
        pthread_t p;
        pthread_create(&p,NULL,ThreadedFunction,&mystruct); //create new thread
    }
}
  • 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-27T18:07:18+00:00Added an answer on May 27, 2026 at 6:07 pm

    You don’t need to “queue” the data coming in from the clients.
    Because TCP do that for you. Flow control of TCP even slows down clients, if the server is too slow to make space to TCP receiving buffer.

    So, probably there is bug in the code of server or client. Maybe client sends ‘\0’ in the end of each line. In that case, the following code would not print all lines:

    if((nbytes=recv(conid, buf, sizeof buf, 0)) <= 0) {
        //handle break in connection
    } else {
        //for this example, just print out data from client to make my point
        buf[nbytes] = 0;
        printf("%s\n",buf);
    }
    

    It is even expected that the 2nd line is the last line what you see, if client sends ‘\0’ at the end of each line.

    For example:

    If client sends the following lines:

    "abc\n\0"
    "def\n\0"
    "ghi\n\0"
    

    TCP will usually send those by using two packets, that contains following:

    "abc\n\0"
    "def\n\0ghi\n\0"
    

    Server usually needs 2 recv calls to receive the incoming data.
    So your server will use 2 print calls:

    printf("%s\n", "abc\n\0\0");
    printf("%s\n", "def\n\0ghi\n\0\0");
    

    And the result output is:

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

Sidebar

Related Questions

I am creating an object server-side which is to have all of the data
Here's my situation: We have an outside provider that will be pushing XML files
Here is the situation: I have a huge data set that I need quick
Greetings! I'm creating a User Control that will display data in a GridView control.
I have an ACE reactor that accepts socket connections and listens for the incoming
Situation: I have a simple XML document that contains image information. I need to
I have an app that communicates with a server that uses HTTP Digest authentication.
Here's the situation: subversion is already installed in the server and I have access
I'm creating (really, re-creating) an app that has existing user and other data in
We have a piece of functionality that is used by several different applications (clients)

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.