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

The Archive Base Latest Questions

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

I’ve developed a client that connects to a server. The client writes something to

  • 0

I’ve developed a client that connects to a server. The client writes something to the server and the server reads and responds back to the client. The client then reads what the server said and both terminate. I wish to extend this allowing the client and server to continue talking for say 3 more time and then terminate. I produced a for loop where inside this loop I handled the code read and write code on both of the server and client, but it is ending up in an infinite loop and writing the text inputted in the first time rather than re asking the user to enter new data.

The server code where the read/write is handled is as follows:

int temp = 0;
char cha [10] = "helloworld";
while(temp = 3){

int rc;
char ch[100];


rc = read(newsockfd, &ch, 100);
    printf("Client sent: %s\n", ch ) ;      

    write(newsockfd, cha + temp, 100);

temp ++;
}


close(sockfd);
close(newsockfd);

This is the client code where read/write is handled:

int temp = 0;
char cha[10] = "abcdefhijk";

while(temp = 3)       
{
int rc;
char ch2 [100];

rc = write(sockfd, cha + temp, 100);

    read(sockfd, &ch2, 100);
    printf("Server said: %s\n", ch2);

temp ++;
}


sleep(2);
close(sockfd);

Also, I am closing the file descriptors after loop is completed.

Any help is greatly appreciated

  • 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-31T23:13:47+00:00Added an answer on May 31, 2026 at 11:13 pm

    Could you provide the loop code also? And are you using blocking or non-blocking calls to read() and write()? (that is, do they return immediately independently of whether data is available (non-blocking), or do they block until something is available (blocking))?

    Update:
    If the code you posted is the actual code, then your while loop is at fault. You check for

    temp = 3
    

    Which is always true, as you are just assigning ‘3’ to temp. You probably mean

    temp < 3
    

    ?

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests

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.