tags:

views:

48

answers:

1

Why does socket_base not have a send() method? Basically, I would like to use boost::asio's sockets like linux socket descriptors: whether the underlying socket is UDP or TCP it doesn't matter, you can call read(), write(), sendto(), etc... on them.

Is there a more proper solution than just writing a wrapper class around asio's udp & tcp socket classes?

+2  A: 

You need to use a particular type of socket, like boost::asio::ip::tcp::socket, which is a stream-based TCP socket, or boost::asio::ip::udp::socket, which is for datagrams. The socket_base class is simply a base class which stores common functionality. The actual socket classes contain all the transfer functions you're looking for, like send and receive functions.

As you can see in the documentation, each socket type has send and receive functions.

Charles Salvia
Yes, but I would like to abstract the socket type so that I don't have to write two sets of functions (one for UDP sockets and one for TCP). For example, in linux I can do send(socket_descriptor,buf,len,flags) and it will work for both UDP and TCP.
Boost.ASIO doesn't use virtual functions in that manner, so you'll need to use templates to be able to write a function that takes any type of socket as a parameter
Charles Salvia