The echo
class implements RFC 862. An echo
object, as a
client, will get back what ever data it sends to an echo
server.
Similarly, an echo
object, as a server, will echo back the data
it receives from its client.
The echo
class is derived from protocol
class, and uses
echo::echobuf
as its stream buffer. echo::echobuf
is in
turn is derived from protocol::protcolbuf
.
In what follows,
e
is a echo
object.
pname
is a transport protocol name and must be either
protocol::tcp
or protocol::udp
.
echo e (pname)
echo
object, e
with pname
as its
transport protocol name.
echo::operator -> ()
echo
object is a smart pointer for the underlying
echobuf
.
// echo server. Serves clients at port 4000. #include <echo.h> #include <stdlib.h> int main () { becho server (protocol::tcp); server->serve_clients (4000); return 1; }
// echo client. Sends "mary had a litte lamb" to the server #include <echo.h> #include <stdlib.h> int main () { becho e(protocol::tcp); e->connect ("kelvin.seas.virginia.edu", 4000); cout << e->rfc_name () << ' ' << e->rfc_doc () << endl; e << "mary had a little lamb\r\n" << flush; char buf [256]; e.getline (buf, 255); cout << "got back: " << buf << endl; return 0; }