Page 1 of 1

qxClientServer with both server and client

PostPosted: Tue Sep 23, 2014 9:29 pm
by exilef
Hello,

I am trying to build a client-server service architecture with the help of qx::service.

The special situation with that architecture is that each instance is at the same time both client and server (serving and accessing the same functions).

What would be the best way to implement that functionality? I checked the example code in qxClientServer and noticed that it uses #defines to fix the role to be either server or client during compilation time. Anything I overlooked?

Thanks!

Re: qxClientServer with both server and client

PostPosted: Wed Sep 24, 2014 6:59 am
by qxorm
Hello,

The special situation with that architecture is that each instance is at the same time both client and server

You need 2 classes because as you said : it uses #defines to fix the role to be either server or client.

So you could imagine to have 2 namespaces, for example named :
- from_client_to_server
- from_server_to_client

Inside these 2 namespaces, you have exactly the same classes and you just inverse the #define in the implementation of the class (.cpp).

To do it automatically and without having to do the job twice (create 2 classes each time), you could imagine to use QxEntityEditor : using a script, I think it should be quite easy to generate the 2 namespaces quickly and without having to deal with 2 structures (copying the qxee project file, execute a UPDATE SQL query on it to change the namespace of all entities, then do another export)...
Please let me know if you want more details about how to do it with QxEntityEditor, or if you want to try to write yourself 2 classes in different namespace.

Re: qxClientServer with both server and client

PostPosted: Wed Sep 24, 2014 3:50 pm
by exilef
Thanks for the quick reply! I still played a bit yesterday and apart from the two namespace solution (which I would like to avoid because of code doubling), I found out that there is another way to do it: just compile and use the server side shared object / dll, i.e. the server part of the qxService sample and make the calls to the server directly via qx::service::execute_client(SERVICE_INSTANCE, "METHOD_NAME"). This can even be wrapped in a macro. Works perfectly and does not need namespace / class doubling.

Re: qxClientServer with both server and client

PostPosted: Wed Sep 24, 2014 7:23 pm
by qxorm
I found out that there is another way to do it: just compile and use the server side shared object / dll, i.e. the server part of the qxService sample and make the calls to the server directly via qx::service::execute_client(SERVICE_INSTANCE, "METHOD_NAME").

Great !