1 // ziop_clt.cc
2 //
3 // This is a variant of the eg2_clt from src/examples/echo that
4 // enables ZIOP, and sends large enough messages to trigger
5 // compression.
6 //
7 // Usage:
8 // ziop_clt -ORBclientTransportRule "* unix,ssl,tcp,ziop" <object reference>
9 //
10
11 #include <echo.hh>
12 #include <omniORB4/omniZIOP.h>
13
14 #include <iostream>
15 #include <fstream>
16 #include <sstream>
17 #include <string>
18
19 using namespace std;
20
hello(Echo_ptr e)21 static void hello(Echo_ptr e)
22 {
23 // Send this source code as the message
24
25 stringstream buf;
26 ifstream stream(__FILE__);
27
28 buf << stream.rdbuf();
29
30 string input = buf.str();
31 CORBA::String_var result = e->echoString(input.c_str());
32
33 cout << "I sent " << input.size() << " characters, and received "
34 << strlen((const char*)result) << "." << endl;
35 }
36
37 //////////////////////////////////////////////////////////////////////
38
main(int argc,char ** argv)39 int main(int argc, char** argv)
40 {
41 try {
42 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
43
44 // Set empty global ZIOP policies. This enables ZIOP with the
45 // default settings.
46 CORBA::PolicyList pl;
47 omniZIOP::setGlobalPolicies(pl);
48
49 if (argc != 2) {
50 cerr << "usage: ziop_clt -ORBclientTransportRule \"* unix,ssl,tcp,ziop\""
51 << " <ior>" << endl;
52 return 1;
53 }
54
55 CORBA::Object_var obj = orb->string_to_object(argv[1]);
56
57 Echo_var echoref = Echo::_narrow(obj);
58
59 if (CORBA::is_nil(echoref)) {
60 cerr << "Can't narrow reference to type Echo (or it was nil)." << endl;
61 return 1;
62 }
63
64 hello(echoref);
65
66 orb->destroy();
67 }
68 catch(CORBA::SystemException& ex) {
69 cerr << "Caught a CORBA::" << ex._name() << endl;
70 }
71 catch(CORBA::Exception& ex) {
72 cerr << "Caught CORBA::Exception: " << ex._name() << endl;
73 }
74 return 0;
75 }
76