Background
This document describes how to install ice in a unbuntu environment and write an ice application in C + +
About Ice
Ice is the Zeroc Open Source Communication protocol product, its full name is: The Internet Communications engine, translated into Chinese is the Internet communications engines, is a popular object-oriented toolkit, so that we can build distributed applications at the lowest cost. Ice allows us to focus on the development of application logic, which handles all the underlying programming of the network interface, so we don't have to consider the details of opening the network connection, serialization and deserialization of the network data transfer, attempts to fail the connection, and so on.
The first part
Download
SOURCE Download Link: poke here
Compiling the installation
Tar zxvf ice-3.6.0.tar.gz
CD Ice-3.6.0/cpp
Make
Make install
Problems & Workarounds encountered
1) Connectioni.cpp:28:19:error:bzlib.h: no file or directory
sudo apt-get install Libmcpp-dev
2).. /freeze/transactioni.h:15:20:error:db_cxx.h: No file or directory
To install Berkeley DB, refer to: poke here
BDB Environment Configuration:
Export db_home=/usr/local/berkeleydb.4.6
Path= $PATH: $DB _home/bin
. . BASHRC
Part II
1. Create an ice file Printer.ice
module Demo { interface Printer { void printstring (string s ); };};
2.Compiling a Slice Definition for C + +
$ slice2cpp Printer.ice
3. Create Server.cpp
#include <Ice/Ice.h>#include<Printer.h>using namespacestd;using namespaceDemo;classPrinteri: PublicPrinter { Public:Virtual voidPrintstring (Const string& S,Constice::current&);};voidprinteri::p rintstring (Const string& S,Constice::current&) {cout<< s <<Endl;}intMain (intargcChar*argv[]) {intStatus =0; ice::communicatorptr ic;Try{IC=ice::initialize (argc, argv); Ice::objectadapterptr Adapter=IC->createobjectadapterwithendpoints ("Simpleprinteradapter","default-p 10000"); Ice::objectptrObject=NewPrinteri;adapter->add (Object, Ic->stringtoidentity ("Simpleprinter")); adapter-activate (); IC-Waitforshutdown ();} Catch(Constice::exception&e) {Cerr<< e <<Endl;status=1;} Catch(Const Char*msg) {Cerr<< msg <<Endl;status=1;}if(IC) {Try{IC-destroy ();} Catch(Constice::exception&e) {Cerr<< e <<Endl;status=1;}}returnstatus;}
4. Create Client.cpp
#include <Ice/Ice.h>#include<Printer.h>using namespacestd;using namespaceDemo;intMain (intargcChar*argv[]) {intStatus =0; ice::communicatorptr ic;Try{IC=ice::initialize (argc, argv); Ice::objectprxBase= Ic->stringtoproxy ("simpleprinter:default-p 10000"); Printerprx Printer= Printerprx::checkedcast (Base);if(!printer)Throw "Invalid Proxy";p Rinter->printstring ("Hello world!");} Catch(Constice::exception&ex) {Cerr<< ex <<Endl;status=1;} Catch(Const Char*msg) {Cerr<< msg <<Endl;status=1;}if(IC) ICS-destroy ();returnstatus;}
5. Testing
1. Environment configuration
Export ice_home=/opt/ice-3.6.0
Export ld_library_path= $LD _library_path: $DB _home/lib64:/home/bran/ice-3.6.0/cpp
$ c +-I.-i$ice_home/include-c Printer.cpp Server.cpp
$ c + +-o server printer.o server.o-l$ice_home/lib-lice-liceutil
$ c +-I.-i$ice_home/include-c Printer.cpp Client.cpp
$ c + O client printer.o client.o-l$ice_home/lib-lice-liceutil
Ubuntu installation Ice Record