Sign in to follow this  
AbanoubNassem

boost asio async_read is not invoking the handler

Recommended Posts

well, i made a static-lib. and i created this three classes in

Connection
[url="http://pastebin.com/Ea9nLFUw"]http://pastebin.com/Ea9nLFUw[/url]

ConnectionFactory
[url="http://pastebin.com/jeAg0cr7"]http://pastebin.com/jeAg0cr7[/url]

Server
[url="http://pastebin.com/x2ywkKCy"]http://pastebin.com/x2ywkKCy[/url]

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

in my main.cpp

[code] #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;
}[/code]

but the Receive() method is not invoking the handle_Receive() method!, can some one tell me what am doing wrong here!!!!???

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='hplus0603' timestamp='1307060403' post='4818918']
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.
[/quote]

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this