From 0b2cb14874fdc657090ef0ba7814796193996056 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sat, 18 Oct 2003 08:06:05 +0000 Subject: [PATCH] Se agrega nuevos tests de sockets ahora con una nueva lib, socket++, porque la anterior, skstream, estaba incompleta. --- links.txt | 3 ++ tests/socket++/Makefile | 15 +++++++++ tests/socket++/udp_receiver.cpp | 51 +++++++++++++++++++++++++++++ tests/socket++/udp_transmiter.cpp | 53 +++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 tests/socket++/Makefile create mode 100644 tests/socket++/udp_receiver.cpp create mode 100644 tests/socket++/udp_transmiter.cpp diff --git a/links.txt b/links.txt index 7301aba..b03465a 100644 --- a/links.txt +++ b/links.txt @@ -3,3 +3,6 @@ http://www.starlinux.net/staticpages/index.php?page=20020720164837437 GTK--: http://www.gtkmm.org/gtkmm2/docs/tutorial/html/ + +Socket++: +http://members.aon.at/hstraub/linux/socket++/ diff --git a/tests/socket++/Makefile b/tests/socket++/Makefile new file mode 100644 index 0000000..b3f0882 --- /dev/null +++ b/tests/socket++/Makefile @@ -0,0 +1,15 @@ +# +# $Id$ +# + +# Opciones para el compilador. +CXXFLAGS=-ansi -pedantic -Wall -g +LDFLAGS=-lsocket++ + +TARGETS=udp_receiver udp_transmiter + +# Regla por defecto. +all: $(TARGETS) + +clean: + rm -f $(TARGETS) *.o diff --git a/tests/socket++/udp_receiver.cpp b/tests/socket++/udp_receiver.cpp new file mode 100644 index 0000000..9944614 --- /dev/null +++ b/tests/socket++/udp_receiver.cpp @@ -0,0 +1,51 @@ +/* vim: set ts=4 sw=4 : + * + * Prueba de 'receptor' tipo broadcast con socket++. + * + * Para compilar: + * g++ -lsocket++ -o udp_receiver udp_receiver.cpp + * + * Necesita paquetes libsocket++ y libsocket++-dev que se pueden bajar de + * http://members.aon.at/hstraub/linux/socket++/ + * + * $Id$ + * + */ + +#include +#include +#include + +using namespace std; + +int main(int argc, char* argv[]) { + // Necesita argumentos. + if (argc != 3) { + cerr << "Faltan argumentos: " << endl; + cerr << "\t" << argv[0] << " host port" << endl; + return 1; + } + + // Obtengo puerto. + string host = argv[1]; + unsigned port; + { + stringstream str(argv[2]); + str >> port; + } + + char buf[4096]; + isockinet is(sockbuf::sock_dgram); + + is->bind(port); + is->recvtimeout(5); + + cout << "Escuchando en " << is->localhost() << ':' << is->localport() + << "." << endl; + + while (is.getline(buf, 4096)) { + cout << buf << endl; + } + + return 0; +} diff --git a/tests/socket++/udp_transmiter.cpp b/tests/socket++/udp_transmiter.cpp new file mode 100644 index 0000000..3a72095 --- /dev/null +++ b/tests/socket++/udp_transmiter.cpp @@ -0,0 +1,53 @@ +/* vim: set ts=4 sw=4 : + * + * Prueba de 'transmisor' tipo broadcast con socket++. + * + * Para compilar: + * g++ -lsocket++ -o udp_transmiter udp_transmiter.cpp + * + * Necesita paquetes libsocket++ y libsocket++-dev que se pueden bajar de + * http://members.aon.at/hstraub/linux/socket++/ + * + * $Id$ + * + */ + +#include +#include +#include +// FIXME - no portable. +#include + +using namespace std; + +int main(int argc, char* argv[]) { + // Necesita argumentos. + if (argc != 3) { + cerr << "Faltan argumentos: " << endl; + cerr << "\t" << argv[0] << " host port" << endl; + return 1; + } + + // Obtengo host y puerto. + string host = argv[1]; + unsigned port; + { + stringstream str(argv[2]); + str >> port; + } + + osockinet os(sockbuf::sock_dgram); + os->connect(host.c_str(), port); + os->sendtimeout(5); + + cout << "Transmitiendo a " << os->peerhost() << ':' << os->peerport() + << " desde " << os->localhost() << ':' << os->localport() << "." + << endl; + + while (true) { + os << "Hola mundo!" << endl; + sleep(1); + } + + return 0; +} -- 2.43.0