X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/6e0194f46ac77c18bfeabf84ef94a32f23e41073..a9d033a0a6748c192d30c9c65ebcc8b1a96cd43b:/Server/src/transmitter.cpp?ds=sidebyside diff --git a/Server/src/transmitter.cpp b/Server/src/transmitter.cpp index d4306e3..de940f9 100644 --- a/Server/src/transmitter.cpp +++ b/Server/src/transmitter.cpp @@ -26,25 +26,59 @@ // #include "plaqui/server/transmitter.h" +#include #include #include +#ifdef DEBUG +# include +#endif // DEBUG -using namespace Plaqui; +using namespace std; -Transmitter::Transmitter(std::string host, int port): - Connection(sockbuf::sock_dgram) { - // FIXME - deberia ir en run(). +namespace PlaQui { + +namespace Server { + +Transmitter::~Transmitter(void) { +#ifdef DEBUG + cerr << __FILE__ << ": destructor." << endl; +#endif // DEBUG +} + +Transmitter::Transmitter(string& _host, Connection::Port& _port): + Connection(sockbuf::sock_dgram, _host, _port) { +#ifdef DEBUG + cerr << __FILE__ << ": _host = " << _host + << " | _port = " << _port << endl; +#endif // DEBUG socket->connect(host.c_str(), port); + // Reasigno el host y puerto bien, tanto de este objeto como los que se + // environ para indicar su valor correcto. + host = socket->peerhost(); + port = socket->peerport(); + _host = socket->peerhost(); + _port = socket->peerport(); } +/// \todo debría dar una excepción (?) void Transmitter::real_run(void) { - // FIXME - debería tirar una excepción? - if (!socket->is_open()) { - std::cerr << "No se pudo conectar a " << socket->peerhost() << - ":" << socket->peerport() << "." << std::endl; - } else { - std::cerr << "Conectado a " << socket->peerhost() << - ":" << socket->peerport() << "." << std::endl; +#ifdef DEBUG + cerr << __FILE__ << ": real_run()." << endl; +#endif // DEBUG + // No hace nada, porque solo actua cuando se manda algo con send(). + while (!stop) { + Glib::usleep(1000); } } +void Transmitter::send(const string& data) { +#ifdef DEBUG + cerr << __FILE__ << ": send(data = " << data << ")." << endl; +#endif // DEBUG + socket << data << flush; +} + +} // namespace Server + +} // namespace PlaQui +