added examples
[libt2n] / examples-codegen / example1-client / client.cpp
CommitLineData
208db683
JT
1// for socket_client_connection
2#include <socket_client.hxx>
3
4// include generated library header
5#include "t2nexample_client.hxx"
6
7int main(int argc, char** argv)
8{
9 // use a local socket (a.k.a "unix domain socket")
10 // if you want to connect to a tcp/ip server you pass the port and server name to the constructor
11 libt2n::socket_client_connection sc("./socket");
12 // this generated class has a method for each of our exported procedures
13 cmd_group_t2nexample_client cc(sc);
14
15 bool throwok=false;
16
17 // exceptions are passed back to the client transparently
18 try
19 {
20 // call the remote procedure (we pass "throw" to cause a exception to be thrown)
21 cc.testfunc("throw");
22 }catch(libt2n::t2n_runtime_error &e){
23 throwok=(std::string(e.what())=="throw me around");
24 }
25
26 // call remote procedure and check the return value is correct
27 return ( throwok && ( cc.testfunc("hello") == "hello, testfunc() was here" ) )
28 ? EXIT_SUCCESS : EXIT_FAILURE;
29}