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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:53:13+00:00 2026-05-31T12:53:13+00:00

I am implementing both server and client side of a simple file download program.

  • 0

I am implementing both server and client side of a simple file download program. Client side requests file names from the server with get command, and server responses quickly. While server writes to the socket, clients reads the socket and prints out the buffer. After that time, program starts not to interpret my commands unless I press ‘Enter’ twice. (You can see it from Shell output below)

After debugging, I found out that it is because of the buffer size. While server writing to the socket; everything works properly if I use a small buffer size. But if I use a larger buffer size such as 1024, that problem occurs. How can I get rid of this issue?

#define F_BUFF_SIZE 1024

On server side:

/* ... */
if(!strcmp(buffer, "list\n")) {

    char buff[F_BUFF_SIZE];
    bzero(buff, F_BUFF_SIZE);

    pt_ret = pthread_create(&thread_id, NULL, getfiles, (void*) buff);
    pthread_join(thread_id, pt_ret);

    n = write(sock, buff, F_BUFF_SIZE);
/* ... */

On client side:

/* ... */
char buffer[F_BUFF_SIZE];

bzero(buffer, F_BUFF_SIZE);
n = read(b_sock, buffer, F_BUFF_SIZE - 1);

if (n < 0) {
#ifdef _DEBUG_
    fprintf(stderr, "Error: Could not read from the socket.\n");
#endif
    return 0;
}

fputs(buffer, stdout);
/* ... */

Shell:

Opening socket: OK!
Connecting: OK!
 # list
client
project1.mk
cs342.workspace
client.c
project1.project
cs342.workspace.session
server
cs342_wsp.mk
server.c
cs342.tags
 # get
 # take
get 
# take
Unknown command.
...
  • 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-31T12:53:14+00:00Added an answer on May 31, 2026 at 12:53 pm

    There is no magic to having a smaller buffer size, this is just exposing that you have an error elsewhere. Joerg’s comment is an important point – you need to be reading the same amount of data that you are writing. I’m wondering if there’s also an issue with how you populate buff. You need to make sure that you are not overrunning the end of the buffer, or forgetting to add a null terminator to the end of the string.

    By the way, it is important to read the size – 1; you’re correct to do this since read won’t append a null terminator to a string. You just need to be sure that you’re writing that amount because otherwise there can be problems.

    You must have some issue along these lines – this would explain why changing the size avoids the problem because problems like this are only exposed when the numbers line up perfectly. Running the program in valgrind may expose the issue (look for invalid write errors).

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

Sidebar

Related Questions

I have a java requirment contains both client and server side program. Server side
What are the best frameworks for implementing both client and server REST frameworks in
I wanted to implement web hooks in python. Both at server end and client
I am making a protocol, client and server which provide file transfer functionality similar
I am implementing a client/server application where video streaming occurs between two computers (in
Both the client and the server are internal, each has a certificate signed by
I've got a client/server setup that I am implementing using a WCF Service (
I'm implementing a client/server application using UDP transmissions. Here is my part of my
When implementing a client/server solutions, one of the questions you always need to answer
I am implementing a database application and I will use both JavaDB and MySQL

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.