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

  • Home
  • SEARCH
  • 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 6550527
In Process

The Archive Base Latest Questions

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

I am currently writing a simple client and server program for both Windows and

  • 0

I am currently writing a simple client and server program for both Windows and Unix. At this point in time I just wanted to create a simple client and server where the server would echo back the message to the client. I have got this to work in the windows environment but am having a very strange issue for the Unix environment. It seems after the message is received the server to print this out but then seems to get stuck. It will not attempt to send the message back to the client or even print another thing after it. I have attached the endless loop that I am using for the server. I have used the same code for the windows version and it seems to work 100% so i have no idea why this does not.

Ps This is my first post so sorry If i left anything out. I am also using Cygwin to run my Unix Code if that helps.

Thanks in advance.

 for(;;)
    {

        char buf[1024];
        int cc = recv(newsockfd, buf, sizeof(buf), 0);
        if (cc == 0)
        {
            exit(0);
        }
        buf[cc] = NULL;
        printf("message received: %s\n", buf);
        printf("This Never Prints!");
        send(newsockfd, buf, cc, 0 );
        memset(&buf, '\0', sizeof(buf));
    }  
  • 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-25T12:13:36+00:00Added an answer on May 25, 2026 at 12:13 pm

    Richard,

    It’s possible that the second line doesn’t print because stdout isn’t flushed.
    If your socket is non-blocking, perhaps the send() isn’t working because an error in the subsequent memset corrupts the data before it’s sent.

    Try changing the last three statements to

    printf("This should print!\n"); // Add a newline
    fflush(stdout);                 // Flush the output for good measure
    send(newsockfd, buf, cc, 0);    // Unchanged
    memset(buf, '\0', sizeof(buf)); // buf is already an address.
    

    Does that change the behavior?

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

Sidebar

Related Questions

I'm currently writing a simple client/server in Java using sockets. I want the server
I'm writing simple server/client in c, where server temporary stores message from client and
I'm currently writing a simple cross platform app with Node.js on the server and
I'm in the process of writing a Java client and server, and they're both
I'm writing a client and server application. Right now I've just been developing it
I am writing a client/server app in C++ and need to realize simple protocol
I am currently writing a simple, timer-based mini app in C# that performs an
I'm currently writing a simple .sh script to parse an Exim log file for
I'm currently writing a very simple game engine for an assignment and to make
I am currently developing android XMPP client to communicate with the Tigase server setup

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.