FFrpc python client lib

Source: Internet
Author: User

Abstract:

Ffrpc can easily build c ++ servers. In online game server program development, inter-process communication is very important, such as the communication between gateserver and gameserver or dbserver. While ffrpc can make inter-process communication very simple, because the ffrpc broker mode encapsulates location independence, such as gate calls the gameserver interface only need to know the service name of the other party, so that the relationship between nodes in the program and the system topology is perfectly consistent. This also makes the system architecture clearer and more robust and easy to maintain.

Previously, ffrpc only provided the Implementation of c ++ server/client. In the development of online game server programs, it often needs to communicate with C ++ server in other languages, such as some tool programs, some web configuration and management backend accesses common scripting languages for greater agility. For example, if you develop a gm background, you can use python to develop a web page, and the gm background command must be sent to the c ++ server for execution. Therefore, the scripting language needs to call the C ++ server interface. Therefore, ffrpc provides the python client gift library ffrpc-py.

Features
  • C ++ server uses binary protocol to transmit data. However, it is very difficult to manually use python Binary packages. Fortunately, google protobuf and thrift are two major artifacts, google protobuf has been widely accepted in the field of server program development. Therefore, because C ++ server uses protobuf (or prefers thrift like me) to define interfaces, it is easier to communicate with scripts.
  • For C ++ server, communication is asynchronous because C ++ server is generally a single thread in the logic layer. To maintain high concurrency, asynchronous io operations are an inevitable choice. However, for scripts such as python, the synchronous call model is generally used, while the ffrpc communication mode requires all interfaces to be req <-> ret one-to-one, ffrpc-py calls the c ++ server interface. It only needs to specify the input message and then call the interface to receive the returned message, which is as direct as calling a local function. This is also the significance of rpc lib.
  • Ffrpc-py supports protobuf and thrift. Of course, it must be consistent with the communication protocol used by c ++ server.
Example

In this example, c ++ sever thrift is used as an example. Because the tutorial in the ffrpc example directory has implemented a c ++ echo server, this example uses ffrpc-py to call the echo interface.

The thrift definition file is:

: : 

 

Use ffrpc-py to call the echo interface:

  

    HOST = = 10246= ffclient_t(HOST, PORT, 1.5) = ttypes.echo_thrift_in_t(=, req, ret, ( %

 

Description of ffrpc interface parameters:

  • The parameter of the ffclient_t (HOST, PORT, 1.5) constructor is the listening address and PORT of the broker. Ffrpc-py only needs to know the broker location. As to which server interface is called, the broker determines whether the target server is in the same process as the broker or connected through the network, ffrpc-py does not need to know the details.
  • The call interface calls a remote server interface. The parameter is the service name registered by the c ++ server interface. ffrpc-py can locate the target server by knowing the service name.
  • The second parameter of call is the request parameter.
  • The third parameter of call is the type of the message returned by the c ++ server. If the call returns true, the message will be automatically assigned a value.
  • The fourth parameter is the message namespace. For example, if the namespace is defined when the thrift file is defined, the fourth parameter must be filled in the namespace, this is the same as the message registered by C ++ server. If C ++ server does not have a message namespace, skip this parameter.
  • If the Call interface is successful, True is returned. If the Call fails, false is returned. At the same time, the error_msg interface can output the error cause.
Summary

Ffrpc provides python lib for communication between py and c ++ server, which makes it easier to use python writing tools and the background.

At the same time, ffrpc will support php and the corresponding client lib will be available soon.

Github: https://github.com/fanchy/FFRPC

The implementation of c ++ server see previous: http://www.cnblogs.com/zhiranok/p/ffrpc_client_server.html

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.