简体   繁体   English

节俭客户端 - 服务器多个角色

[英]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++). 我正在尝试制作thrift服务器(python)和客户端(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). 客户端应该注册(调用服务器的功能并等待),服务器应该在同一端口上侦听N(N-> 100k)传入连接(客户端)。 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"? 我有点困惑,第一个问题是“这可以在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! 谢谢!

Consider using boost::asio for your client side, though depending on your level of C++, the code may seem too dense. 考虑将boost :: asio用于客户端,但根据您的C ++级别,代码可能看起来过于密集。

If you're looking for a simple example, take a look at: http://www.linuxhowtos.org/C_C++/socket.htm 如果您正在寻找一个简单的示例,请查看: 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. 客户端可以实现为单线程循环,在查询套接字以查找任何传入信息,执行计算以及将结果发布回套接字之间交替。

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. 因为,你说你从客户端调用函数时遇到问题,这里有一个带有Java服务器和C ++客户端的样本Thrift代码,客户端调用服务器中的函数。 http://fundoonick.blogspot.com/2010/06/sample-thrift-program-for-server-in.html http://fundoonick.blogspot.com/2010/06/sample-thrift-program-for-server-in.html

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM