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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:19:12+00:00 2026-06-15T23:19:12+00:00

I actually tried a client server code using TCP Select. I don’t know why

  • 0

I actually tried a client server code using TCP Select. I don’t know why is the garbage value printed after every request from the client is printed on the server

Here is the server code
https://www.dropbox.com/s/qgd87fby6tif9q6/server.c

Here is the client code
https://www.dropbox.com/s/qlv1im06gfw5i1w/client.c

  • 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-15T23:19:13+00:00Added an answer on June 15, 2026 at 11:19 pm

    You’re treating the message received on the server as a string but aren’t sending a nul terminator from the client. This leads to old content in recv_buf and possibly further down the stack being displayed as printf scans memory for the next byte with value 0. You could address this by either sending a nul terminator from the client by changing you send call to include the string terminator in your message

    send(sockfd, send_buf, strlen(send_buf) + 1, 0);
    

    or in the server by adding a nul terminator after receiving the message

    recv_buf[nbytes_recvd] = '\0';
    

    [Original answer retained below in case you also want to remove the newline from messages. And because that’d have inadvertently fixed your problem.]

    “garbage value” doesn’t give us a lot to go on…

    At a guess, these characters may be newlines (single character with value 0x0D). From the fgets man page (my emphasis)

    fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A terminating null byte (aq\0aq) is stored after the last character in the buffer.

    The string your client reads may end in a newline. If you don’t want to send this to the server, you could remove it by adding

    size_t len = strlen(send_buf);
    if (len > 0 && send_buf[len-1] == '\n') {
        send_buf[len-1] = '\0';
    }
    

    to your client, between its calls to fgets and send.

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

Sidebar

Related Questions

I have a server in linux using the Berkeley_sockets and I create a TCP
I have a TCP server and client, with an established socket. Let's say I
Below is my code for Linux. I am implementing a client/server application and below
Someone tried to recreate smarty in js: // actually from a template file, not
I have tried just about everything for getting the Kinect for Windows to actually
I tried :s%/{//g and :s%/\{//g . How do I find and replace (remove, actually)
I'm actually looking for how to use Amazon SES on phpbb3. I tried to
I'm trying to learn Lisp (elisp, actually), and I tried writing the following function
I'm working on a client/server application in C#, and I need to get Asynchronous
Is there any way to crop a photo using client side JavaScript only? When

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.