Hola Manuel, todo puede ser mucho más sencillo si utilizas la clase
Ice::Application [1] tanto en el cliente como en el servidor:
class Server : virtual public Ice::Application {
virtual int run (int, char*[]) {
Ice::ObjectAdapterPtr adapter = communicator()->
createObjectAdapterWithEndpoints(
"HolaMundoAdapter", "default -p 10000");
Ice::ObjectPtr object = new HolaMundoI;
adapter->add(object, communicator()->stringToIdentity("HolaMundo"));
adapter->activate();
communicator()->waitForShutdown();
return 0;
}
};
int main (int argc, char *argv[]) {
Server server;
return server.main(argc, argv);
}
Un saludo,
David.
[1] http://zeroc.com/doc/Ice-3.2.1/manual/Cpps.9.3.html (Apartado 8.3.1)
P.D.: la última versión del manual de Ice es la 3.2.1.
El mar, 30-10-2007 a las 19:54 +0100, Manuel David Jiménez Patiño
escribió:
> Aquí está el maldito hola mundo en C++ paso a paso. Sacado del libro
> que recomendaba Tobias
>
> ice-3.2.0.pdf
>
>
> Crea el fichero Printer.ice y copia esto
>
> module Demo {
> interface Printer {
> void printString(string s);
> };
> }
>
> Compílalo así:
>
> $ slice2cpp Printer.ice
>
> te genera un Printer.h y un Printer.cpp porque tú lo vales.
>
>
> Crea el fichero Server.cpp y sin miedo escribe lo siguiente:
>
>
>
>
> #include <Ice/Ice.h>
> #include <Printer.h>
> using namespace std;
> using namespace Demo;
>
> class PrinterI : public Printer {
> public:
> virtual void printString(const string& s,
> const Ice::Current&);
> };
> void
> PrinterI::
> printString(const string& s, const Ice::Current&)
> {
> cout << s << endl;
> }
>
> int
> main(int argc, char* argv[])
> {
> int status = 0;
> Ice::CommunicatorPtr ic;
> try {
> ic = Ice::initialize(argc, argv);
>
>
>
> //----------------------------Creamos un adaptador de
> objetos------------------------------------------------
>
>
> Ice::ObjectAdapterPtr adapter
> = ic->createObjectAdapterWithEndpoints(
> "SimplePrinterAdapter", "default -p 10000");
>
>
>
> //--------------------------Indicamos al adaptador de objetos la
> existencia de sirvientes-----------------
>
> //el sirviente es el metodo PrinterI, fin del misterio
>
> Ice::ObjectPtr object = new PrinterI;
> adapter->add(object, ic->stringToIdentity("SimplePrinter"));
>
>
>
>
>
> //------------------------Activamos el adaptador de objetos
> --------------------------------------------------
>
>
> adapter->activate();
> ic->waitForShutdown();
> } catch (const Ice::Exception& e) {
>
> cerr << e << endl;
> status = 1;
> } catch (const char* msg) {
> cerr << msg << endl;
> status = 1;
> }
> if (ic) {
> try {
> ic->destroy();
> } catch (const Ice::Exception& e) {
> cerr << e << endl;
> status = 1;
> }
> }
> return status;
> }
>
>
> Lo que significa viene en ice-3.2.0.pdf y si no tienes ni papa de
> inglés el manual de David Vallejo también lo explica bastante bien.
>
> Compila:
>
> $ c++ -I. -I$ICE_HOME/include -c Printer.cpp Server.cpp
> $ c++ -o server Printer.o Server.o \-L$ICE_HOME/lib -lIce -lIceUtil
>
> Con esto obtienes un ejecutable llamado server
>
>
> Ahora toca escribir el cliente, crea Client.cpp:
>
> #include <Ice/Ice.h>
> #include <Printer.h>
> using namespace std;
> using namespace Demo;
>
>
> int main(int argc, char* argv[])
> {
> int status = 0;
> Ice::CommunicatorPtr ic;
> try {
> ic = Ice::initialize(argc, argv);
>
>
>
> //Obtenemos el proxy del objeto remoto(esto es conectar con el
> servidor de antes, ya está)
>
>
> Ice::ObjectPrx base = ic->stringToProxy(
> "SimplePrinter:default -p 10000");
>
>
>
> PrinterPrx printer = PrinterPrx::checkedCast(base);
>
> if (!printer)
> throw "Invalid proxy";
> printer->printString("Hello World!");
> } catch (const Ice::Exception& ex) {
> cerr << ex << endl;
> status = 1;
> } catch (const char* msg) {
> cerr << msg << endl;
> status = 1;
> }
> if (ic)
> ic->destroy();
> return status;
> }
>
>
> Compila:
>
> $ c++ -I. -I$ICE_HOME/include -c Printer.cpp Client.cpp
> $ c++ -o client Printer.o Client.o -L$ICE_HOME/lib -lIce -lIceUtil
>
> te crea un ejecutable que se llama
>
> client
>
>
>
> Ahora abre un terminal vete al directorio en cuestión y escribe:
>
> ./server
>
> Por último abre un terminal vete al directorio en cuestión y
> escribe:
>
> ./client
>
> Ale ya tenemos el dichoso hola mundo!!!!
>
> Saludos, si tengo tiempo haré una receta formal.
>
> ***********************+
> "Hay gente pa to y patas", Mi antiguo profesor de geografía.
>
>
>
>
>
>
>
>
>
>
> On 10/30/07, Tobias Diaz <[EMAIL PROTECTED]> wrote:
> El mejor manual: ice-3.2.0.pdf de ZeroC con ejemplos y hola
> mundos para
> todos...
>
> On Tue, 30 Oct 2007 18:52:32 +0100
> "Manuel David Jiménez Patiño" <[EMAIL PROTECTED]>
> wrote:
>
> > Gracias Tobias ya he solucionado el problema, era lo que tú
> decias.
> >
> > He creado un directorio llamado Hola_mundo_C++
> > he metido en él los archivos:
> >
> > Client.cpp
> > Server.cpp
> > Makefile
> >
> > y fuera del directorio Hola_mundo_C++ he colocado los
> archivos:
> >
> > config
> > hello.ice
> >
> > lo que pasa es que ahora al hacer:
> >
> > $make
> >
> > me dice el cachondo:
> >
> > g++ -I. -I/usr/include -c -o Server.o Server.cpp
> > Server.cpp: In member function 'virtual int Server::run(int,
> char**)':
> > Server.cpp:17: error: no se puede asignar un objeto de tipo
> abstracto
> > 'UCLM::Hello'
> > hello.h:183: nota: porque las siguientes funciones virtual
> son puras
> > en 'UCLM::Hello':
> > hello.h:196: nota: virtual void UCLM::Hello::puts(const
> > std::string&, const Ice::Current&)
> > make: *** [Server.o] Error 1
> >
> >
> >
> > No sé que está fallando mi fichero hello.ice es el
> siguiente:
> >
> > module UCLM {
> > interface Hello {
> > void puts(string str);
> > };
> > };
> >
> >
> > De todas formas no me fio mucho de estos archivos el
> Server.cpp
> > traía un include helloI.h cuando el makefile genera un
> hello.h.
> >
> > Por lo que voy a probar el hola mundo del manual de David
> Vallejo. (En
> > mi modesta opinión creo es un manual bastante completo y
> viene muy
> > bien para empezar)
> >
> > Saludos.
> >
> >
> >
> *********************************************************************
> > ************** "Un documental ha sido líder de audiencia, se
> llevan
> > las gordas y la inteligencia... Ojalá fuera verdad" Mago de
> Oz
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On 10/30/07, Tobias Diaz <[EMAIL PROTECTED]> wrote:
> > >
> > > Pues resulta que make tiene que usar por algún motivo el
> archivo de
> > > configuración (../config), el motivo es que lo tiene en la
> regla
> > > para "all":
> > > all: config patatin ... patatan
> > >
> > > y si vemos la regla "config":
> > >
> > > config: ../config
> > > patatin patatan
> > >
> > > Pues eso quiere decir que para la regla "config" necesaria
> para
> > > "all" necesita el archivo "../config" que:
> > > - O existe y no lo busca
> > > - No existe y lo intenta crear, y si no puede: "falta XXX
> necesario
> > > para el objetivo XXX"
> > >
> > > En resumidas cuentas: create el archivo ../config con la
> > > configuración necesaria para el ejemplo, si ya hay alguno
> por ahí,
> > > ponlo en el directorio padre de donde ejecutes make.
> > >
> > >
> > > On Tue, 30 Oct 2007 17:32:35 +0100
> > > "Manuel David Jiménez Patiño" <[EMAIL PROTECTED]>
> wrote:
> > >
> > > > Hola a todos estaba intentado realizar un hola mundo en
> C++ con
> > > > el middleware ZeroC Ice.
> > > >
> > > > He sacado los archivos de aquí;
> > > >
> > > > https://arco.inf-cr.uclm.es/svn/public/prj/ice-hello/
> > > >
> > > > La referencia se encuentra en Crysol:
> > > >
> > > > http://crysol.inf-cr.uclm.es/node/619
> > > >
> > > > copio todos los archivos tal y como vienen:
> > > >
> > > > EL makefile es el siguiente:
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > GENERATED = hello
> > > >
> > > > all: config $(GENERATED).cpp Server Client
> > > >
> > > > Server: Server.o $(GENERATED).o $(GENERATED)I.o
> > > >
> > > > Server.o: Server.cpp
> > > >
> > > > Client: Client.cpp $(GENERATED).o
> > > >
> > > > $(GENERATED): $(GENERATED).cpp
> > > >
> > > > $(GENERATED).o: $(GENERATED).cpp
> > > >
> > > > $(GENERATED).cpp: $(GENERATED).ice
> > > > slice2cpp $<
> > > >
> > > > $(GENERATED).ice: ../$(GENERATED).ice
> > > > ln -s $< $@
> > > >
> > > > config: ../config
> > > > ln -s $< $@
> > > >
> > > > clean:
> > > > $(RM) *.o
> > > > $(RM) Server Client
> > > >
> > > > vclean: clean
> > > > $(RM) *~ $(GENERATED).cpp $(GENERATED).h
> > > > $(RM) config *.ice
> > > >
> > > >
> > > >
> > > > pero al hacer:
> > > >
> > > > $make
> > > >
> > > > me sale la siguiente lindeza:
> > > >
> > > > make: *** No hay ninguna regla para construir el
> objetivo
> > > > `../config', necesario para `config'. Alto.
> > > >
> > > >
> > > >
> > > > estoy buscando en ejemplos por internet y en ejemplos
> propios de
> > > > makefilesque yo tenía por ahí, pero todos ellos son
> demasiado
> > > > sencillos.
> > > >
> > > > ¿Me pueden ayudar?, no obstante seguiré probando y
> ejecutando.
> > > >
> > > > Saludos.
> > > >
> > > >
> *****************************************************************
> > > > **** *********************************
> > > > De los elementos de la tabla periódica mis favoritos
> siempre
> > > > fueron los
> > > > raros.
> > >
> > > _______________________________________________
> > > CRySoL mailing list
> > > http://crysol.inf-cr.uclm.es/
> > >
> https://arco.inf-cr.uclm.es/cgi-bin/mailman/listinfo/crysol
> > >
> > >
> > >
>
> _______________________________________________
> CRySoL mailing list
> http://crysol.inf-cr.uclm.es/
> https://arco.inf-cr.uclm.es/cgi-bin/mailman/listinfo/crysol
>
>
>
> _______________________________________________
> CRySoL mailing list
> http://crysol.inf-cr.uclm.es/
> https://arco.inf-cr.uclm.es/cgi-bin/mailman/listinfo/crysol
_______________________________________________
CRySoL mailing list
http://crysol.inf-cr.uclm.es/
https://arco.inf-cr.uclm.es/cgi-bin/mailman/listinfo/crysol