Skip to main content
GameDev.net gamedev.net
🔒 Locked

boost asio async_read is not invoking the handler

Started by AbanoubNassem Jun 2, 2011 at 11:54 PM 2 replies 3.6k views
Original Post
AbanoubNassem
AbanoubNassem
well, i made a static-lib. and i created this three classes in

Connection
http://pastebin.com/Ea9nLFUw

ConnectionFactory
http://pastebin.com/jeAg0cr7

Server
http://pastebin.com/x2ywkKCy

and i drevid from the static-lib and used this classes and it's working perfect

in my main.cpp

#include <iostream>
#include "auth_proto.h"
#include <Server.h>
#include <ConnectionFactory.h>
#include "AuthConnectionFactory.h"

using namespace std;
int main()
{
Auth_Setup();
try
{
boost::asio::io_service io_service;
boost::shared_ptr<ConnectionFactory> fact (new AuthConnectionFactory(io_service));
Server s(io_service,"5.113.195.156",9959,fact);
io_service.run();
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}

return 0;
}


but the Receive() method is not invoking the handle_Receive() method!, can some one tell me what am doing wrong here!!!!???
hplus0603
hplus0603
If you run "netstat -napl -t tcp" when the server is running, does the server show up as listening?
Why are you specifying a specific IP address to the endpoint for listening? Generally, you want to listen on 0.0.0.0 which means "all interfaces."
Also, I seem to recall that your socket needs to be open()-ed before you can pass it into accept(), but I'm not 100% sure.
enum Bool { True, False, FileNotFound };
AbanoubNassem
AbanoubNassem

If you run "netstat -napl -t tcp" when the server is running, does the server show up as listening?
Why are you specifying a specific IP address to the endpoint for listening? Generally, you want to listen on 0.0.0.0 which means "all interfaces."
Also, I seem to recall that your socket needs to be open()-ed before you can pass it into accept(), but I'm not 100% sure.


the client is blocking anyconnection through "127.0.0.1" or so therefor am using an IP, and i dont think there is something wrong with the socket since it's working and the Receive() method is receiving but it's not calling handl_Receive() so i can use this data got me?
pablo24
pablo24
In your "Connection" paste, line 77: bytes_transferred is of type size_t (which is always unsigned as per 7.17 and 7.18.3 of the C99 standard)

bytes_transferred <= 0 will always evaluate to false unless bytes_transferred is zero, you probably meant to write if (bytes_transferred > 0)

You should always post the up-to-date code, there was no way to tell you this from anything you showed on stackoverflow.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.