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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:54:54+00:00 2026-06-15T12:54:54+00:00

I’m working on a c program in linux. I need to use client server

  • 0

I’m working on a c program in linux. I need to use client server programming. I used read and write and it worked fine. But after using more than 20 read and write in both server and client, it has stopped working. That is I don’t receive any output for that. Line. I don’t understand what is the problem because am using the very same lines.

bzero(&hl,200);
read(a,hl,50*sizeof(char));
printf("%s",hl);

In client side,

bzero(&hl,200);
strcpy(hl,"hello");
write(a,hl,50*sizeof(char));
printf("%s",hl);

Also, am not able to get the return value and print it. While I used it in debian, I got the return value and able to print. Now, am in Ubuntu (at home). It’s not printing return value now. No error too! Is it anything to do with OS?

Please help me figure out the problem.

UPDATED:

In server,

int c:
s=read(a,&c,sizeof(int));
printf(“choice: %d”,c);

In client,

scanf(“%d”,&ch);
s=write(sd,&ch,sizeof(int));

Both has size 4. But, in client I got garbage value while I print the choice.

  • 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-15T12:54:56+00:00Added an answer on June 15, 2026 at 12:54 pm

    You throw away the return value of read, so you have no idea how many bytes you’ve read. What if it’s less than 50?

    Change:

    read(a,hl,50*sizeof(char));
    

    To:

    int readBytes = 0;
    do
    {
        int r = read(a, hl + readBytes, 50 - readBytes);
        if (r <= 0)
            return; // or however you want to handle an error
        readBytes += r;
    } while (readBytes < 50);
    

    That will ensure you actually read 50 bytes.

    You are imagining that TCP somehow “glues” those 50 bytes together. But the system has no idea that those 50 bytes are a message — only your code does. So it’s your code’s job to glue them back together. TCP does not preserve application message boundaries — that is the application’s job.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

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.