asio C++ library

PrevUpHomeNext

Socket Iostreams

Asio includes classes that implement iostreams on top of sockets. These hide away the complexities associated with endpoint resolution, protocol independence, etc. To create a connection one might simply write:

ip::tcp::iostream stream("www.boost.org", "http");
if (!stream)
{
  // Can't connect.
}

The iostream class can also be used in conjunction with an acceptor to create simple servers. For example:

io_service ios;

ip::tcp::endpoint endpoint(tcp::v4(), 80);
ip::tcp::acceptor acceptor(ios, endpoint);

for (;;)
{
  ip::tcp::iostream stream;
  acceptor.accept(*stream.rdbuf());
  ...
}
See Also

ip::tcp::iostream, basic_socket_iostream, iostreams examples.

Notes

These iostream templates only support char, not wchar_t, and do not perform any code conversion.


PrevUpHomeNext