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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:28:29+00:00 2026-05-30T02:28:29+00:00

I’m developing a 3d (first/third person) game and I’m trying to make it multiplayer

  • 0

I’m developing a 3d (first/third person) game and I’m trying to make it multiplayer using TCP sockets. I’m using the boost asio library for this, and I’m in a little over my head. I’ve played with the tutorials and examples a bit on the boost asio doc page and they compiled/ran/worked just fine, I’m just a little confused as to how everything works.

Right now I’m just trying to make the server accept messages from the client, and print the message after receiving it. When I execute the code below (it compiles/links/runs fine), nothing happens. More specifically, the client appears to successfully send the message, and the server never seems to receive the message.

Client code:

ClientFramework::ClientFramework() :
    mResolver(mIOService)
{
}

bool ClientFramework::Initialize()
{
    try
    {
        tcp::resolver::query query("localhost", "daytime");
        tcp::resolver::iterator it = mResolver.resolve(query);
        tcp::socket socket(mIOService);
        boost::asio::connect(socket, it);

        std::string s = "hello world";
        boost::system::error_code e;
        socket.write_some(boost::asio::buffer(s.c_str(), s.size()), e);

        if (e)
        {
            throw boost::system::system_error(e);
        }
    } catch (std::exception& e)
    {
        gLog << LOG_ERROR << e.what() << "\n";
    }

    return true;
}

Server code:

ServerFramework::ServerFramework() :
    mAcceptor(mIOService, tcp::endpoint(tcp::v4(), 13))
{
}

bool ServerFramework::Initialize()
{
    mIOService.run();
    StartAccept();

    return true;
}

void ServerFramework::StartAccept()
{
    Connection::ptr conn =
        Connection::create(mAcceptor.get_io_service());
    mAcceptor.async_accept(conn->Socket(),
        boost::bind(&ServerFramework::HandleAccept, this, conn,
            boost::asio::placeholders::error));
}

void ServerFramework::HandleAccept(Connection::ptr conn,
    const boost::system::error_code& error)
{
    if (!error)
    {
        conn->Initialize();
    }

    StartAccept();
}

Connection::ptr Connection::create(boost::asio::io_service& io_service)
{
    return ptr(new Connection(io_service));
}

tcp::socket& Connection::Socket()
{
    return mSocket;
}

void Connection::Initialize()
{
    boost::asio::async_read(mSocket, boost::asio::buffer(buf, BUFFER_SIZE),
        boost::bind(&Connection::handle_read, shared_from_this(),
          boost::asio::placeholders::error,
          boost::asio::placeholders::bytes_transferred));
}

Connection::Connection(boost::asio::io_service& io_service) :
    mSocket(io_service)
{
}

void Connection::handle_read(const boost::system::error_code& e, size_t size)
{
    std::string s(buf, size);
    gLog << LOG_INFO << s << "\n";

    boost::asio::async_read(mSocket, boost::asio::buffer(buf, BUFFER_SIZE),
        boost::bind(&Connection::handle_read, shared_from_this(),
          boost::asio::placeholders::error,
          boost::asio::placeholders::bytes_transferred));
}
  • 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-30T02:28:30+00:00Added an answer on May 30, 2026 at 2:28 am

    It does not look like your io_service has any work to do when you invoke run().

    bool ServerFramework::Initialize()
    {
        mIOService.run(); // <-- you don't check the return value here
        StartAccept();
    
        return true;
    }
    

    it will return the number of handlers executed, I suspect it is zero. Try invoking it after async_accept()

    bool ServerFramework::Initialize()
    {
        StartAccept();
        mIOService.run();
    
        return true;
    }
    

    Though, it isn’t entirely obvious by your limited code snippets where you invoke ServerFramework::Initialize(). I suggest editing your question with a short, self contained, correct example that we can compile with little to no effort. Your current code will not compile without additional boilerplate stuff, like main().

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
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 am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.