views:

342

answers:

2

Hi,

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!

+1  A: 

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.

Artem
Thrift has been proposed as one way to do it ...Key point is that they must be in different pl (python and c++),and I just wonder can this be done in Thrift ???Also, because a large number of clients are expected, multithreading on server side should be avoided.
dexter
Well, my answer covers the client side. I'm afraid my python knowledge is not up to par to answer about the server side.
Artem
A: 

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 :)

Nikhil Jindal