qxClientServer with both server and client

Open discussion on QxOrm library

qxClientServer with both server and client

Postby exilef » Tue Sep 23, 2014 9:29 pm

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!
exilef
 
Posts: 3
Joined: Tue Sep 23, 2014 9:22 pm

Re: qxClientServer with both server and client

Postby qxorm » Wed Sep 24, 2014 6:59 am

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.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: qxClientServer with both server and client

Postby exilef » Wed Sep 24, 2014 3:50 pm

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.
exilef
 
Posts: 3
Joined: Tue Sep 23, 2014 9:22 pm

Re: qxClientServer with both server and client

Postby qxorm » Wed Sep 24, 2014 7:23 pm

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 !
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Open discussion

Who is online

Users browsing this forum: No registered users and 4 guests