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

The Archive Base Latest Questions

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

i have a problem with data transfert in boost::asio. with the following code :

  • 0

i have a problem with data transfert in boost::asio.
with the following code :

Server.cpp

void        Server::accept(void)
{
    Network::ptr connection = Network::create(this->my_acceptor.get_io_service());
    this->my_acceptor.async_accept(connection->getSocket(), bind(&Server::endCmd, this, connection, placeholders::error));
}

void        Server::endCmd(Network::ptr connection, const boost::system::error_code& error)
{
    if (!error)
        {
            connection->Swrite("BIENVENUE");
            this->accept();
        }
}

Network.cpp

void        Network::Sread(void)
{
    async_read(this->socket, buffer(this->rbuffer), bind(&Network::endRead, shared_from_this(), placeholders::error));
}

void            Network::endRead(const error_code& error)
{
    if (!error)
        {
            this->rcv_msg = this->rbuffer.c_array();
            std::cout << this->rcv_msg << std::endl;
            this->Sread();
        }
}

void            Network::Swrite(std::string msg)
{
    this->msg = msg;
    async_write(this->socket, buffer(this->msg, (int)this->msg.size()), bind(&Network::endWrite, shared_from_this(), placeholders::error));
}

void            Network::endWrite(const error_code &error)
{
    if (!error)
    {
        this->Sread();
    }
}

tcp::socket&    Network::getSocket(void)
{
    return (this->socket);
}

Network::ptr                Network::create(io_service &ios)
{
    return (ptr(new Network(ios)));
}

When i send a string like “Hello world” to the server with telnet, he write the following content : bug with my serveur

Who can tell me why the server is writting many unknow characters ?

  • 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-26T20:53:44+00:00Added an answer on May 26, 2026 at 8:53 pm

    It looks like the rbuffer.c_array() isn’t a null terminated string but just a array of characters. Printing a character array to cout assumes that the array is null terminated, which in this case causes the memory after the end of the array being included in the output.

    You should create a std::string from the data before trying to print it:

    std::string received(rbuffer.c_array(), rbuffer.size());
    std::cout << received;
    

    (Assuming rbuffer has a size() method or something equivalent)

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

Sidebar

Related Questions

I have a problem POSTing data via HTTPS in Java. The server response is
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I have the following problem in my Data Structures and Problem Solving using Java
I have a problem returning data back to the function I want it returned
I have a problem with data in UITableView. I have UIViewController, that contains UITableView
i have problem to correctly bind data to WPF Chart. When i'm setting ItemsSource
I have a problem with a data-bound DataGrid control, in that despite each column
I have a problem with binding data using BindingSource, typed dataset and DataGridView. My
I have problem when I try insert some data to Informix TEXT column via
I have a problem accessing JSON data. I'm new to JSON and jquery so

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.