Requirement: a mobile or web game server requires that the maintenance be as simple as possible, and the framework be as concise as possible,CodeThe number of servers should not be too large. Considering that one person is not dedicated for server maintenance, it cannot be too difficult for O & M.
First, raknet must be used. The available game server framework is rare. This is one of the open-source frameworks. The underlying layer provides a complete and reliable UDP protocol, and the upper layer has a complete encapsulation and has to be used.
Second, the client uses C ++ and Lua, and the logic part fully uses Lua. The server needs to perform some verification, so the related logic should be partially reused.
The technical test conclusions are as follows:
1. Create a game server using an HTTP server. It is very simple and crude, and it is very easy to do. However, in the HTTP service, the server cannot actively send requests, so some interaction needs are almost impossible. After discussion, give up.
2. raknet is fully written in C ++, making maintenance difficult. The official recommendation of raknet's Patcher server is PostgreSQL, because some features of MySQL are not supported properly. For example, it is very slow to intercept a long string in the database.
3. Database middleware (ORM). Options: C ++ database (ODB) and Python database (sqlalchemy.
4. interface generator swig. The database used to register all c ++ libraries (such as raknet) in other languages in a semi-automated manner. The experiment is difficult and feasible. There is still a problem: registration of callback functions, registration of Remote Procedure Call RPC has not been investigated.
5. There are two ways to use Python: one is to register the underlying library of C ++ to Python, and the other is to allow C ++ to call the interface of the python module.
6. There is no major problem in the technical implementation of Lua. The Code related to the server logic is basically determined by Lua.
7. New discoveries in the morning: Lua and Python mixed programming: lunatic python. Being two-way means that it allows Lua inside python, python inside Lua, Lua inside python inside Lua, python inside Lua inside python, and so on. domineering side leakage. I don't know if you dare to use it. In addition, the LUA-jit optimized version of lunatic python is Lupa. The URLs are:
Http://labix.org/lunatic-python
Http://pypi.python.org/pypi/lupa/0.9
8. A new discovery in the morning: cython. Supports compiling code that looks like python and C with a special syntax. You can compile it into a dynamic link library at the C language level. This greatly reduces overhead and speeds up mathematical operations and function calls. It can be used for optimization in the middle and late stages of the project. It is hereby recorded.
Important advantages and disadvantages:
1. According to Baidu, the C ++ ORM library ODB is one of the best choices, but I carefully studied the help manual and practical experiments all day long, it is found that this library requires users to use the new features of C ++ 11, and a large number of use of special compiler syntaxes such as # pragma. Table associations are implemented using a variety of different types of smart pointers. In addition, the underlying layer of this library provides a boost-like modified library, and provides more intelligent pointers than boost, such as lazy_shared_ptr. These advanced functions will inevitably be used. (I would like to say that this product is not c ++ .)
In addition, because C ++ needs to be compiled, ODB is not fully automated during use. Its use is decomposed into two major steps: analyze the header file to generate the glue layer, and then compile the link user code and the glue layer.
2. sqlalchemy is easy to use and can be integrated with database initialization and operations through simple design. I have a much higher understanding of Python than C ++ 11 and boost. Its fatal disadvantage is that once Python-related technologies are used, it is necessary to make a lot of effort on the C ++/Python interface.
3. The fatal problem of swig is that the database porting process is a process that tests the basic syntax skills of C ++/other languages and is very challenging. Implementation difficulty: 4 and a half stars, but you can try it.
We plan to design the Server framework under the above conditions. The remaining problem is how C ++ calls the python interface in a simple way. We are expected to draw a conclusion today.
------------------------------------------------------
Conclusion: fully use Python + Lua (lunatic Python) to write servers
Among them, the raknet library uses swig to register all important interfaces with python, and directly uses python to write high-performance servers! Some advanced features at the time of migration require careful reading of swig's online documentation, which has passed the test. Welcome to the discussion.
In this way, the focus of all technologies is shifted to Python. I hope all Python fans can see this article.Article. In fact, I recently want to learn Ruby =