Este módulo está implementado por las clases PlaQui::Server::ControlServer
y PlaQui::Server::ControlClient.
- \subsection page_server_general_control_http Ventajas del protocolo HTTP.
+ \subsubsection page_server_general_control_http Ventajas del protocolo HTTP.
Las ventajas de montar el protocolo del servidor sobre el protocolo
HTTP son muchas. Las más destacables son las más obvias.
+++ /dev/null
-// vim: set noexpandtab tabstop=4 shiftwidth=4:
-//----------------------------------------------------------------------------
-// PlaQui
-//----------------------------------------------------------------------------
-// This file is part of PlaQui.
-//
-// PlaQui is free software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 2 of the License, or (at your option) any later
-// version.
-//
-// PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
-// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-// details.
-//
-// You should have received a copy of the GNU General Public License along
-// with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
-// Place, Suite 330, Boston, MA 02111-1307 USA
-//----------------------------------------------------------------------------
-// Creado: jue nov 13 00:53:38 ART 2003
-// Autores: Leandro Lucarella <llucare@fi.uba.ar>
-//----------------------------------------------------------------------------
-//
-// $Id$
-//
-
-#include "plaqui/server/controlclient.h"
-#include "plaqui/server/string.h"
-#include <iostream>
-#include <exception>
-#include <vector>
-
-using namespace std;
-using namespace PlaQui::Server;
-
-ControlClient* client = NULL;
-
-void on_error(const Runnable::Error& code, const string& desc) {
- cerr << "--------------------------------------------------------" << endl;
- cerr << "Error en el cliente:" << endl;
- cerr << "Código: " << code << endl;
- cerr << "Descripción: " << desc << endl;
- cerr << "--------------------------------------------------------" << endl;
-}
-
-void on_finished(void) {
- client = NULL;
-}
-
-void on_connected(void) {
- cout << " Conectado! :-)" << endl;
-}
-
-void on_ok_received(const string& body) {
- cout << " Respuesta recibida: OK! :-D" << endl;
- cout << " Body: " << body << endl;
-}
-
-void on_frame_received(const string& frame) {
- cout << " Frame recibido! :-D" << endl;
- cout << frame << endl;
-}
-
-void on_error_received(unsigned code) {
- cout << " Respuesta recibida: Error nro " << code << "! :-(" << endl;
-}
-
-int main(int argc, char* argv[]) {
-
- // Termina con mas informacion si hay una excepcion no manejada.
- set_terminate (__gnu_cxx::__verbose_terminate_handler);
-
- // Mensaje de bienvenida.
- cout << "Client test. Modo de uso: " << endl;
- cout << "\t" << argv[0] << " [host] [port]" << endl;
- cout << "Luego se envian comandos con el siguiente formato:" << endl;
- cout << "\t <destino> <comando> [<arg 1>] [<arg 2>] [...] [<arg N>]" << endl;
-
- // Parámetros.
- string host = "localhost";
- if (argc > 1) {
- // Obtengo host.
- host = argv[1];
- }
- // Obtengo puerto.
- Connection::Port port = 7522;
- if (argc > 2) {
- to(argv[2], port);
- }
-
- // Inicializa threads.
- Glib::thread_init();
-
- try {
- // Corre el cliente.
- client = new ControlClient(host, port);
- client->signal_error().connect(SigC::slot(on_error));
- client->signal_finished().connect(SigC::slot(on_finished));
- client->signal_connected().connect(SigC::slot(on_connected));
- client->signal_ok_received().connect(SigC::slot(on_ok_received));
- client->signal_error_received().connect(SigC::slot(on_error_received));
- client->signal_frame_received().connect(SigC::slot(on_frame_received));
- client->run();
- char buf[BUFSIZ];
- while (cin.getline(buf, BUFSIZ)) {
- if (!client) {
- break;
- }
- vector<string> v = String(buf).split(' ');
- switch (v.size()) {
- case 0:
- client->send(Command());
- break;
- case 1:
- client->send(Command(v[0]));
- break;
- case 2:
- client->send(Command(v[0], v[1]));
- break;
- default:
- Command cmd(v[0], v[1]);
- v.erase(v.begin(), v.begin() + 2);
- cmd.set_args(v);
- client->send(cmd);
- break;
- }
- }
- } catch (const sockerr& e) {
- cerr << "Socket Error: " << e.operation() << " | serrno = "
- << e.serrno() << " | errstr = " << e.errstr() << endl;
- if (e.io()) {
- cerr << "Es: non-blocking and interrupt io recoverable error."
- << endl;
- } else if (e.arg()) {
- cerr << "Es: incorrect argument supplied. recoverable error."
- << endl;
- } else if (e.op()) {
- cerr << "Es: operational error. recovery difficult." << endl;
- } else if (e.conn()) {
- cerr << "Es: connection error." << endl;
- } else if (e.addr()) {
- cerr << "Es: address error." << endl;
- } else if (e.benign()) {
- cerr << "Es: recoverable read/write error like EINTR etc." << endl;
- }
- } catch (const exception& e) {
- cerr << "Error: " << e.what() << endl;
- } catch (const char* e) {
- cerr << "Error: " << e << endl;
- } catch (...) {
- cerr << "Error desconocido!" << endl;
- }
-
- return 0;
-}
+++ /dev/null
-<?xml version="1.0" encoding="iso-8859-1" ?>
-<planta>
- <bomba nombre="bomba0" id="0">
- <entrega>50,00</entrega>
- <color>
- <rojo>255</rojo>
- <verde>0</verde>
- <azul>0</azul>
- </color>
- <conector>
- <salida>codo1</salida>
- </conector>
- <orientacion>0</orientacion>
- <x>32</x>
- <y>64</y>
- </bomba>
- <codo nombre="codo1" id="1">
- <caudal>40,00</caudal>
- <conector>
- <entrada>bomba0</entrada>
- <salida>tubo2</salida>
- </conector>
- <orientacion>0</orientacion>
- <x>128</x>
- <y>64</y>
- </codo>
- <tubo nombre="tubo2" id="2">
- <caudal>40,00</caudal>
- <conector>
- <entrada>codo1</entrada>
- <salida>division3</salida>
- </conector>
- <orientacion>0</orientacion>
- <x>160</x>
- <y>128</y>
- </tubo>
- <empalme nombre="division3" id="3">
- <tipo>division</tipo>
- <conector>
- <salida>codo9</salida>
- <salida>codo4</salida>
- <entrada>tubo2</entrada>
- </conector>
- <caudal>40,00</caudal>
- <orientacion>2</orientacion>
- <x>128</x>
- <y>224</y>
- </empalme>
- <codo nombre="codo4" id="4">
- <caudal>40,00</caudal>
- <conector>
- <salida>tubo5</salida>
- <entrada>division3</entrada>
- </conector>
- <orientacion>3</orientacion>
- <x>64</x>
- <y>256</y>
- </codo>
- <tubo nombre="tubo5" id="5">
- <caudal>30,00</caudal>
- <conector>
- <entrada>codo4</entrada>
- <salida>tanque6</salida>
- </conector>
- <orientacion>0</orientacion>
- <x>64</x>
- <y>320</y>
- </tubo>
- <tanque nombre="tanque6" id="6">
- <capacidad>150,00</capacidad>
- <inicial>75,00</inicial>
- <color>
- <rojo>0</rojo>
- <verde>0</verde>
- <azul>0</azul>
- </color>
- <conector>
- <entrada>tubo5</entrada>
- <salida>exclusa18</salida>
- </conector>
- <orientacion>0</orientacion>
- <x>64</x>
- <y>416</y>
- </tanque>
- <codo nombre="codo7" id="7">
- <caudal>4,00</caudal>
- <conector>
- <entrada>exclusa18</entrada>
- <salida>drenaje8</salida>
- </conector>
- <orientacion>0</orientacion>
- <x>192</x>
- <y>448</y>
- </codo>
- <drenaje nombre="drenaje8" id="8">
- <conector>
- <entrada>codo7</entrada>
- </conector>
- <orientacion>0</orientacion>
- <x>224</x>
- <y>512</y>
- </drenaje>
- <codo nombre="codo9" id="9">
- <caudal>20,00</caudal>
- <conector>
- <salida>tubo10</salida>
- <entrada>division3</entrada>
- </conector>
- <orientacion>1</orientacion>
- <x>224</x>
- <y>224</y>
- </codo>
- <tubo nombre="tubo10" id="10">
- <caudal>25,00</caudal>
- <conector>
- <salida>codo12</salida>
- <entrada>codo9</entrada>
- </conector>
- <orientacion>0</orientacion>
- <x>256</x>
- <y>128</y>
- </tubo>
- <empalme nombre="union11" id="11">
- <tipo>union</tipo>
- <conector>
- <entrada>codo12</entrada>
- <entrada>exclusa13</entrada>
- <salida>tubo15</salida>
- </conector>
- <caudal>45,00</caudal>
- <orientacion>0</orientacion>
- <x>320</x>
- <y>64</y>
- </empalme>
- <codo nombre="codo12" id="12">
- <caudal>30,00</caudal>
- <conector>
- <entrada>tubo10</entrada>
- <salida>union11</salida>
- </conector>
- <orientacion>3</orientacion>
- <x>256</x>
- <y>64</y>
- </codo>
- <exclusa nombre="exclusa13" id="13">
- <conector>
- <salida>union11</salida>
- <entrada>bomba14</entrada>
- </conector>
- <orientacion>0</orientacion>
- <estado>1</estado>
- <x>416</x>
- <y>64</y>
- </exclusa>
- <bomba nombre="bomba14" id="14">
- <entrega>15,00</entrega>
- <color>
- <rojo>0</rojo>
- <verde>0</verde>
- <azul>0</azul>
- </color>
- <conector>
- <salida>exclusa13</salida>
- </conector>
- <orientacion>1</orientacion>
- <x>480</x>
- <y>64</y>
- </bomba>
- <tubo nombre="tubo15" id="15">
- <caudal>20,00</caudal>
- <conector>
- <entrada>union11</entrada>
- <salida>codo16</salida>
- </conector>
- <orientacion>0</orientacion>
- <x>352</x>
- <y>128</y>
- </tubo>
- <codo nombre="codo16" id="16">
- <caudal>25,00</caudal>
- <conector>
- <salida>drenaje17</salida>
- <entrada>tubo15</entrada>
- </conector>
- <orientacion>2</orientacion>
- <x>352</x>
- <y>224</y>
- </codo>
- <drenaje nombre="drenaje17" id="17">
- <conector>
- <entrada>codo16</entrada>
- </conector>
- <orientacion>3</orientacion>
- <x>416</x>
- <y>256</y>
- </drenaje>
- <exclusa nombre="exclusa18" id="18">
- <conector>
- <entrada>tanque6</entrada>
- <salida>codo7</salida>
- </conector>
- <orientacion>0</orientacion>
- <estado>1</estado>
- <x>128</x>
- <y>448</y>
- </exclusa>
-</planta>
+++ /dev/null
-// vim: set noexpandtab tabstop=4 shiftwidth=4:
-//----------------------------------------------------------------------------
-// PlaQui
-//----------------------------------------------------------------------------
-// This file is part of PlaQui.
-//
-// PlaQui is free software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 2 of the License, or (at your option) any later
-// version.
-//
-// PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
-// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-// details.
-//
-// You should have received a copy of the GNU General Public License along
-// with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
-// Place, Suite 330, Boston, MA 02111-1307 USA
-//----------------------------------------------------------------------------
-// Creado: jue nov 13 00:53:38 ART 2003
-// Autores: Leandro Lucarella <llucare@fi.uba.ar>
-//----------------------------------------------------------------------------
-//
-// $Id$
-//
-
-#include "plaqui/server/receiver.h"
-#include "plaqui/server/string.h"
-#include <iostream>
-#include <exception>
-
-using namespace std;
-using namespace PlaQui::Server;
-
-void on_frame_received(const string& frame) {
- cout << " Frame recibido! :-D" << endl;
- cout << frame << endl;
-}
-
-int main(int argc, char* argv[]) {
-
- // Termina con mas informacion si hay una excepcion no manejada.
- set_terminate (__gnu_cxx::__verbose_terminate_handler);
-
- // Mensaje de bienvenida.
- cout << "Receiver test. Modo de uso: " << endl;
- cout << "\t" << argv[0] << " [port] [host]" << endl;
-
- // Parámetros.
- Connection::Port port = 7528;
- if (argc > 1) {
- // Obtengo puerto.
- to(argv[1], port);
- }
- string host = "localhost";
- if (argc > 2) {
- // Obtengo host.
- host = argv[2];
- }
-
- // Inicializa threads.
- Glib::thread_init();
-
- try {
- // Corre el cliente.
- Receiver receptor(port, host);
- receptor.signal_frame_received().connect(SigC::slot(on_frame_received));
- receptor.run(false);
- } catch (const sockerr& e) {
- cerr << "Socket Error: " << e.operation() << " | serrno = "
- << e.serrno() << " | errstr = " << e.errstr() << endl;
- if (e.io()) {
- cerr << "Es: non-blocking and interrupt io recoverable error."
- << endl;
- } else if (e.arg()) {
- cerr << "Es: incorrect argument supplied. recoverable error."
- << endl;
- } else if (e.op()) {
- cerr << "Es: operational error. recovery difficult." << endl;
- } else if (e.conn()) {
- cerr << "Es: connection error." << endl;
- } else if (e.addr()) {
- cerr << "Es: address error." << endl;
- } else if (e.benign()) {
- cerr << "Es: recoverable read/write error like EINTR etc." << endl;
- }
- } catch (const exception& e) {
- cerr << "Error: " << e.what() << endl;
- } catch (const char* e) {
- cerr << "Error: " << e << endl;
- } catch (...) {
- cerr << "Error desconocido!" << endl;
- }
-
- return 0;
-}
+++ /dev/null
-// vim: set noexpandtab tabstop=4 shiftwidth=4:
-//----------------------------------------------------------------------------
-// PlaQui
-//----------------------------------------------------------------------------
-// This file is part of PlaQui.
-//
-// PlaQui is free software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 2 of the License, or (at your option) any later
-// version.
-//
-// PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
-// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-// details.
-//
-// You should have received a copy of the GNU General Public License along
-// with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
-// Place, Suite 330, Boston, MA 02111-1307 USA
-//----------------------------------------------------------------------------
-// Creado: Sat Oct 18 18:18:36 2003
-// Autores: Leandro Lucarella <llucare@fi.uba.ar>
-//----------------------------------------------------------------------------
-//
-// $Id$
-//
-
-#include "plaqui/server/connection.h"
-#include "plaqui/server/server.h"
-#include "plaqui/server/string.h"
-#include <socket++/sockinet.h>
-#include <glibmm/timer.h>
-#include <iostream>
-#include <exception>
-
-using namespace std;
-using namespace PlaQui::Server;
-
-Server* server = NULL;
-
-void on_error(const Runnable::Error& code, const string& desc) {
- cerr << "--------------------------------------------------------" << endl;
- cerr << "Error en el servidor:" << endl;
- cerr << "Código: " << code << endl;
- cerr << "Descripción: " << desc << endl;
- cerr << "--------------------------------------------------------" << endl;
-}
-
-void on_finished(void) {
- cerr << "Murió el servidor!" << endl;
- server = NULL;
-}
-
-int main(int argc, char* argv[]) {
-
- // Termina con mas informacion si hay una excepcion no manejada.
- set_terminate (__gnu_cxx::__verbose_terminate_handler);
-
- // Bienvenida.
- cout << "PlaQui Server. Modo de uso: " << endl;
- cout << "\t" << argv[0] << " [planta] [puerto]" << endl;
-
- // Acepta argumentos.
- string filename = "prueba.xml";
- Connection::Port port = 7522;
- if (argc > 1) {
- // Obtengo nombre del archivo de la planta.
- filename = argv[1];
- // Si tiene 2 parámetros.
- if (argc > 2) {
- // Obtengo puerto.
- to(argv[2], port);
- }
- }
-
- // Inicializa threads.
- Glib::thread_init();
-
- try {
- // Crea el server (empieza a escuchar).
- server = new Server(filename, port);
- } catch (const sockerr& e) {
- cerr << "Socket Error: " << e.operation() << " | serrno = "
- << e.serrno() << " | errstr = " << e.errstr() << endl;
- if (e.io()) {
- cerr << "Es: non-blocking and interrupt io recoverable error."
- << endl;
- } else if (e.arg()) {
- cerr << "Es: incorrect argument supplied. recoverable error."
- << endl;
- } else if (e.op()) {
- cerr << "Es: operational error. recovery difficult." << endl;
- } else if (e.conn()) {
- cerr << "Es: connection error." << endl;
- } else if (e.addr()) {
- cerr << "Es: address error." << endl;
- } else if (e.benign()) {
- cerr << "Es: recoverable read/write error like EINTR etc." << endl;
- }
- return e.serrno();
- } catch (const exception& e) {
- cerr << "Error: " << e.what() << endl;
- return 1;
- } catch (const char* e) {
- cerr << "Error: " << e << endl;
- return 2;
- } catch (...) {
- cerr << "Error desconocido!" << endl;
- return 3;
- }
-
- // Conecto señal para atender errores.
- server->signal_error().connect(SigC::slot(on_error));
-
- // Corre el server.
- server->run(false);
-
- // Espera a que el server se muera.
- while (server) {
- Glib::usleep(1000000);
- }
-
- // Como no detachee el server, lo tengo que eliminar a mano.
- //delete server;
-
- return 0;
-}