Browse Source

Initial commit

master
Pedro Berrocal 5 years ago
commit
ae6c44ee7d
3 changed files with 78 additions and 0 deletions
  1. +33
    -0
      README.md
  2. +7
    -0
      src/Printer.ice
  3. +38
    -0
      src/Server.cpp

+ 33
- 0
README.md View File

@ -0,0 +1,33 @@
# Magic World Server
### Install ZeroC Ice on Ubuntu 16.04
```
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv B6391CB2CFBA643D
sudo apt-add-repository "deb http://zeroc.com/download/Ice/3.7/ubuntu16.04 stable main"
sudo apt-get update
```
Install Ice for C++, Java, Python, PHP, and all Ice services
```
sudo apt-get install zeroc-ice-all-runtime zeroc-ice-all-dev
```
Install Freeze for C++
```
sudo apt-get install libzeroc-freeze-dev zeroc-freeze-utils
```
### Generate headers
```
slice2cpp Printer.ice
```
### Compile
```
c++ -std=c++11 -pthread -I. -DICE_CPP11_MAPPING -c Printer.cpp Server.cpp
```
### Link
```
c++ -pthread -o server Printer.o Server.o -lIce++11
```

+ 7
- 0
src/Printer.ice View File

@ -0,0 +1,7 @@
module Demo
{
interface Printer
{
void printString(string s);
}
}

+ 38
- 0
src/Server.cpp View File

@ -0,0 +1,38 @@
#include <Ice/Ice.h>
#include <Printer.h>
using namespace std;
using namespace Demo;
class PrinterI : public Printer
{
public:
virtual void printString(string s, const Ice::Current&) override;
};
void
PrinterI::printString(string s, const Ice::Current&)
{
cout << s << endl;
}
int
main(int argc, char* argv[])
{
try
{
Ice::CommunicatorHolder ich(argc, argv);
// Server implementation here ...
auto adapter = ich->createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000");
auto servant = make_shared<PrinterI>();
adapter->add(servant, ich->stringToIdentity("SimplePrinter"));
adapter->activate();
ich->waitForShutdown();
}
catch(const std::exception& e)
{
cerr << e.what() << endl;
return 1;
}
return 0;
}

Loading…
Cancel
Save