Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thrift client-server multiple roles

this is my first question, so sorry if the form is wrong!

I'm trying to make thrift server (python) and client (c++). However I need to exchange messages in both direction. Client should register (call server's function and wait), and server should listen on same port for N (N-> 100k) incoming connections (clients). After some conditions are satisfied, server needs to call functions on each client and collect results and interpret them.

I'm little confused, and first questions is "can this be done in Thrift"? Second question is related to mechanism that will allow me bidirectional communication. I guess that I will need two services. One with client's functions other with server's. But I'm confused with calling code. I understand one way communication (calling functions from server), but with calling functions from client side I have a problem.

Any suggestions???

Thanks!

like image 559
dexter Avatar asked May 08 '26 23:05

dexter


2 Answers

Consider using boost::asio for your client side, though depending on your level of C++, the code may seem too dense.

If you're looking for a simple example, take a look at: http://www.linuxhowtos.org/C_C++/socket.htm

It contains both server-side and client-side code. Both sides create a socket and two-way communication is achieved by each side posting data to the socket. The server side is generally multi-threaded (with one thread per connection). The client side can be implemented as a single-threaded loop that alternates between querying the socket for any incoming information, performing computations, and posting results back to the socket.

like image 174
Artem Sokolov Avatar answered May 10 '26 12:05

Artem Sokolov


Since, you say you are having problem with calling functions from client side, here is a sample Thrift code with Java server and C++ client, where the client calls a function in server. http://fundoonick.blogspot.com/2010/06/sample-thrift-program-for-server-in.html

Hope this helps :)

like image 29
Nikhil Jindal Avatar answered May 10 '26 13:05

Nikhil Jindal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!