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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:43:00+00:00 2026-05-26T22:43:00+00:00

Basically I am writing a simple program using the boost socket library… I have

  • 0

Basically I am writing a simple program using the boost socket library… I have two programs a client and a server. the server waits for a connection from the client and when it finds one the client sends the server a message and the server prints out, this works the first time the client queries the server but after a while an strange pattern begins lets say our server was running and I used the client program two times by executing:

./client localhost name message
./client localhost name test

the output 0f the server would first be:
name: message
however next it would display
name: testage

I don’t know why this is happening but I know it must be the server, because the the clients each send a packet independently the server just prints it out… I’m thinking that this has something to do with the socket buffer not being flushed or something of that nature…

anyway heres the sourcecode:
client.cpp
http://pastebin.com/hWpLNqnW

server.cpp
http://pastebin.com/Q4esYwdc

  • 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-26T22:43:01+00:00Added an answer on May 26, 2026 at 10:43 pm

    The read_some call in the server returns the number of bytes read. You should use that value and use it to null terminate the buffer. Something along these lines:

    int len = connection.read_some(boost::asio::buffer(buf), error);
    buf[len] = '\0';
    

    In the first message, the buffer may have been initialized with zeros. The next time, though, it would contain the same contents as the previous iteration. Note that the strcpy(buf,""); call only ends up setting the first byte of buf to zero.

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

Sidebar

Related Questions

I am writing a simple OpenGL program with Qt Creator which basically creates a
I have a logger system which basically is a fancy way of writing my
I am writing a multi-threaded program using OpenMP in C++. At one point my
I'm writing a simple program for file encryption. Mostly as an academic exercise but
Good afternoon, I am writing a simple lexer which is basically a modified version
I'm writing a simple booking program for a car rental (a school assignment). Me
I'm a bit confused. I'm writing a very simple file system that basically: -reads
I'm writing a simple tool for troubleshooting computers. Basically its just a WPF Window
I am writing my own engine using OpenTK (basically just OpenGL bindings for C#,
I am writing a simple class that will basically accept 3 parameters, execute a

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.