X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=examples-codegen%2Fexample1-client%2Fclient.cpp;fp=examples-codegen%2Fexample1-client%2Fclient.cpp;h=e35799e39458fab7184ea9ffe0fdb243faa8bfa1;hp=0000000000000000000000000000000000000000;hb=208db683069afb57aeb0ef0e6897c014b870bb6f;hpb=e8b2809dd8681076434fc2b7cb54b148c3b1cbcb diff --git a/examples-codegen/example1-client/client.cpp b/examples-codegen/example1-client/client.cpp new file mode 100644 index 0000000..e35799e --- /dev/null +++ b/examples-codegen/example1-client/client.cpp @@ -0,0 +1,29 @@ +// for socket_client_connection +#include + +// include generated library header +#include "t2nexample_client.hxx" + +int main(int argc, char** argv) +{ + // use a local socket (a.k.a "unix domain socket") + // if you want to connect to a tcp/ip server you pass the port and server name to the constructor + libt2n::socket_client_connection sc("./socket"); + // this generated class has a method for each of our exported procedures + cmd_group_t2nexample_client cc(sc); + + bool throwok=false; + + // exceptions are passed back to the client transparently + try + { + // call the remote procedure (we pass "throw" to cause a exception to be thrown) + cc.testfunc("throw"); + }catch(libt2n::t2n_runtime_error &e){ + throwok=(std::string(e.what())=="throw me around"); + } + + // call remote procedure and check the return value is correct + return ( throwok && ( cc.testfunc("hello") == "hello, testfunc() was here" ) ) + ? EXIT_SUCCESS : EXIT_FAILURE; +}