What am I thinking when I design a game server? (2)

Source: Internet
Author: User

Six months ago I participated in a hand tour project, the first to be able to dominate the design of the game, this article on the server's architecture, the client will not mention.


For the service side, I would like to be changed from the previous end of the server is definitely not going to get through (see:), because the development cycle of the hand tour is much shorter than the end of the tour, the above set of architecture developed more than 5 years, of course, during the overthrow redo many times. This hand tour is only fast for 6 months and 10 months for slow.


Since the decision not to end the architecture of the tour, everything starting from 0, then quickly set up a usable server is the first principle that I consider, 2nd, I do as a programmer's selfish, try to use the previously unused technology, so that they can contact the wider world.

First of course need to find out whether there are ready-made wheels, I spent 1 months to find the GitHub on those good open source architecture, of which there are two sets of systems I think there is potential, one is NetEase's pomelo, the other is the cloud wind Skynet. In fact, I first know is Skynet, because has been concerned about the cloud wind blog, so he this service side I still have some understanding, I spent a week in detail read the Skynet wiki, and started to install the Skynet, and wrote a few simple HTTP communication examples, And then carefully analyzed the Skynet in the C module, even if you want to use Skynet, my background deployment diagram will be what kind of painting, but finally gave up the Skynet, the reason is that the front end will be used to write a combination of Cocos2dx+lua, I would like to try to see how the client and Server scripting language will be different, at the same time, I also think, Cloud Wind with C message queue, I also mysteryof, and at that time Skynet users are not many, no pioneer can refer to, Skynet itself has not stabilized, cloud wind is a energetic guy, The update is fast. Now that Skynet has been released for 1.0, the next game is very likely that I will use it.


Then I found that node. js, in fact, I can not say that I found that the company has already started using node. js to do the game, I was more curious, so I looked at the site of Nodejs, and saw the comments on the Internet, I think this goods is magical, single-threaded event-driven, feeling relatively simple. Then pomelo into the field of vision, I actually found that netease open source a Nodejs write game server architecture, really Xicongtianjiang, I spent 2 weeks to build, study, test pomelo of various uses, with it copy a chat room code online, during the encounter many problems, I mention the issue basically no one, join Pomelo development QQ Group developers are also few, and netease people problem feedback speed let people cry, and is a high above, do not make any explanation of the problem pose. I changed a few pomelo and gave up on it. But I have to say, pomelo to me behind the design of the Nodejs-based server architecture, I have a large part of the design is to refer to its ideas, but also it led me into the Nodejs world.


In my nearly 1 months of time, but nothing to harvest time, I decided to have a chat, I consulted a lot of seniors and strong friends, they gave a lot of advice and help, also gradually help me clarify what I need to do. But when I started writing code, I was nervous. I do not want to detour, want to start on the right road, I am afraid to go a long way, the results found to be wrong, write any line of code, I am pressure doubled. During that time, I was miserable, tangled, stressed, biting my fingers, I bent my right index finger with a large pressure, and then used teeth to bite the second and third joints of the index finger, the night can not sleep soundly. Finally one day, my good friend XY said a word, let me waking wake up, he said, "first began to write, and then slowly change, which has a beginning to design a good system." So simple a truth, I have heard countless times, but never understood what meaning, this is really shaken to, indeed, I want to start on the right way is obviously too naïve, and I do not need to go wrong and annoyed, struggling, because I do not see far enough.


So I started to do it.


Before I have used JS, but only with JS and HTML to make a Web page, this time to write server, I am a bit sure there is no, first from the language began to learn, I looked at the internet for a long time, and finally bought 2 books, one is Crockford "JavaScript language Essence", Another is Pauling's "Nodejs", the previous one is JS in the server to use that part, JS language actually has three parts, Dom + BOM + basic Core, Dom is manipulating the page elements, the BOM is manipulating the browser, the basic core is the most basic part of the language, And the server just need this part, Crockford writing very good, I quickly understand, and then I spent a few days to collate a document, specifically explaining the basic core of JS language, with it to my other programmer friend, he never used JS, my goal is to understand him, Then I must have understood it thoroughly, but it seems that at last he didn't quite understand ...


Then is the part of the Nodejs, Pauling great God wrote the book is really good, should be I see the explanation Nodejs book the best of the class, according to his book and Nodejs official website API document, I began to write my server, according to my friend's reminder, I first write a single process server, And the main part of the server is the network, so I first use Nodejs net.socket write a TCP server, this only with more than 10 lines of code, NODEJS API design is very good, and the document is also very good, quickly understand, and I give Nodejs mention Issue soon will get reply, this period I also found Nodejs for TPC, but at that time found Nodejs split up or a little worried about, but now merge:


At first, I was going to imitate Pomelo's architecture and cut out the things that I didn't need, but then I gave up, and it wasn't that easy, I was just starting with a simple communication, and I wanted to go through a lot of processes at first, And I think it's also necessary (but I don't think so now), but at first it wasn't so good, it was a big step, and it was easy to pull the egg. XY also reminds me, or from a single process to start the design is better, I accepted his opinion, on the basis of this TCP server slowly increase I think the game must be content, such as database interface, protocol, network. Basically the database + Network + protocol is a complete server, the other game logic can be slowly spread, just this time the client's development also began, I used Luasocket wrote a simple client network library, and my this single process of the server to communicate, and finally, My server ran, the code is very few, I control the live, I feel very happy: https://github.com/rangercyh/nodejs_server


This server only has the most basic ability, and the database can communicate, using TCP and the client to communicate, the protocol is also used by my own design protocol in communication, here to say, at first I was intended to use the PROTOBUF protocol to communicate, and then gave up, because I found protobuf The Nodejs-bound library interface design is very cumbersome and difficult to use. And I do not have that high demand, so I realized the agreement, and then I found that, in fact, I can fully use the JSON format, but the LUA side of the JSON there are a variety of problems, this later I will also mention, this is what I said before, I would like to try the client and the server to use the first price of different languages. The resolution of the agreement to write two sets, and ensure that the problem is still very difficult.


In the next article I will introduce a very magical wheel:)


This article is from "rookie surfaced" blog, please be sure to keep this source http://rangercyh.blog.51cto.com/1444712/1673931

What am I thinking when I design a game server? (2)

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.