
Hello. I am trying to write a simple server, and I am using an asynchronous acceptor to get clients: acceptor.async_accept(crtclient->getSocket(), boost::bind(&Server::gotClient, this, boost::asio::placeholders::error)); As soon as this is executed, my Server::gotClient gets called with ec.message()="An invalid argument was supplied." Apparently the problem is that I am supplying an invalid socket with crtClient->getSocket(), but I can't understand how can this be. crtClient is a boost::shared_ptr<Client>. class Client { ... public: Client (boost::asio::io_service &ioserv, Server &server) : socket_(ioserv), ... {} ... boost::asio::ip::tcp::socket &getSocket () { return socket_; } ... private: boost::asio::ip::tcp::socket socket_; ... }; What could be wrong? Am I constructing socket incorrectly with socket_(ioserv)? Because if I construct it with socket_(ioserv, boost::asio::ip::tcp::v4()), I get the error "Already open" in ec.message(), rather than "An invalid argument was supplied".