Standard. See the INSTALL file in the top directory. This package depends on the dvutil package.
This package provides basic network classes. See the ``Compound Members'' entry in the top menubar.
Declares a class Dv::Net::InetAddress that represents an internet host. It encapsulates gethostbyname and friends.
Declares an iostream specialization Dv::Net::Socket that represents a network connection. Opening a connection is as simple as
Dv::Net::Socket so("server-host", server-port); if (so) { so << "send request" << std::endl; std::string reply; std::getline(so, reply); } else std::cerr << "Connection failed: " << so.strerror() << std::endl;
serversocket.h Declares an class Dv::Net::ServerSocket that represents an internet server.
try { Dv::Net::ServerSocket server(server-port); Dv::Util::ref<Socket> client(server.accept()); std::cerr << "Connection from " << client->host() << ":" << client->port() << std::endl; std::string request; std::string reply; while (std::getline(*client, request) ) *client << reply << std::endl; } catch (Dv::Net::ServerSocketError& e) { std::cerr << e.what() << std::endl; return 1; }
operator<<(ostream&, const A&)
and operator>>(istream&, A&)
can be sent and received over a socket (or another stream) using code such as the following. A a(..); // Send an A object. Dv::Net::Message<A> m_out(a); if (! m_out.send(socket) ) throw std::runtime_error("error sending"); try { // Receive an A object. Dv::Net::Message<A> m_in; m_in.receive(socket); } catch (std::runtime_error e) { // error receiving std::cerr << e.what() << std::endl; } A a_in(m_in);
dvnet-0.9.24 | [ 5 December, 2009] |