Boost logo

Boost :

Subject: [boost] Boost ASIO - Client Request TCP Help..!!
From: Rahul Mathur (srivmuk_at_[hidden])
Date: 2013-10-11 13:18:46


All,

Below is the client request code which makes a CONNECT request to remote
SERVER (having IP & PORT#) but gives error code during send() process -

---
#include <iostream>
#include <string>
#include <boost/asio.hpp>
namespace opp = boost::asio::ip;
struct PacketFormat
{
    unsigned short length;          //Length
    int sequenceNumber;
};
int main(int argc, char* argv[])
{
                std::string port = "8000";
                std::string hostname = "X.X.X.X";
                boost::asio::io_service io_service;
                opp::tcp::resolver resolver(io_service);
                opp::tcp::resolver::query query(hostname, port);
                opp::tcp::resolver::iterator iter = resolver.resolve(query);
                opp::tcp::resolver::iterator end; // End marker.
                // Looking for a successful endpoint connection
                opp::tcp::socket socket(io_service);
                boost::system::error_code error =
boost::asio::error::host_not_found;
                while (error && iter != end)
                {
                        socket.close();
                        socket.connect(*iter++ , error);
                }
                if (error)
                        throw boost::system::system_error(error);
                std::cout << "Connected ..Thanks!! \n" << std::endl;
                PacketFormat pf; // where PacketFormat is struct defined
                pf.length = 236;
                pf.sequenceNumber = 2;
                std::cout << "Sending Logon Message.. . ..!! \n" <<
std::endl;
                std::size_t n = opp::tcp::socket::send(iter,
boost::asio::buffer(&pf));
                if (n < 0)
             std::cerr << "ERROR writing to Server .. . ..\n" << std::endl;
                std::cout << "Logon Message Sent.. . ..Thanks!!\n" <<
std::endl;
                if (n < 0)
                        std::cerr << "ERROR writing to Server .. . ..\n" <<
std::endl;
                std::cout << "Logon Message Sent.. . ..Thanks!!\n" <<
std::endl;
  return 0;
}
__
The error message obtained is -
--
# g++ testclient.cpp -o testclient -lboost_system -lboost_thread
testclient.cpp: In function âint main(int, char**)â:
testclient.cpp:42: error: no matching function for call to
âbuffer(PacketFormat*)â
/usr/local/include/boost/asio/buffer.hpp:704: note: candidates are:
boost::asio::mutable_buffers_1 boost::asio::buffer(const
boost::asio::mutable_buffer&)
/usr/local/include/boost/asio/buffer.hpp:717: note:
boost::asio::mutable_buffers_1 boost::asio::buffer(const
boost::asio::mutable_buffer&, size_t)
/usr/local/include/boost/asio/buffer.hpp:733: note:
boost::asio::const_buffers_1 boost::asio::buffer(const
boost::asio::const_buffer&)
/usr/local/include/boost/asio/buffer.hpp:746: note:
boost::asio::const_buffers_1 boost::asio::buffer(const
boost::asio::const_buffer&, size_t)
/usr/local/include/boost/asio/buffer.hpp:762: note:
boost::asio::mutable_buffers_1 boost::asio::buffer(void*, size_t)
/usr/local/include/boost/asio/buffer.hpp:772: note:
boost::asio::const_buffers_1 boost::asio::buffer(const void*, size_t)
__
Please help for L#42 "tcp::socket::send()" proper call. I believe above
code fine apart from L#42 error.
Thanks!!

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk