Online online game development experience (server side) (1)

xiaoxiao2021-03-06  55

Bromon Originally respects the copyright a multi-person online chess online game project approaches the end, I have participated in the entire design process of the project and completed 90% of the core code. About this project, there are many places worth talking. This series does not intend to put this project how detailed specification, that is what the design documentation should be described, I plan to talk about some things worth noting.

One of this project is that the client is a mobile phone, and the user communicates with the server via mobile networks. Compared with the PC, the mobile phone has extremely weak, and network traffic is expensive. Because in addition to some of the issues of ordinary online games, these two points need to be fully considered in the design.

The first is the choice of development language, because the server is Linux environment, MS technology is directly excluded, as for Mono, I really don't worry. Alternative is C and Java, Java is powerful in network capabilities, short development cycle, has a number of frames and open source support, it is not easy to write faded unacceptable code; C is fast. Comprehensive factors, C easier to turn this project into a bunch of code nightmare, we chose Java.

First, online online games, the first problems are of course how to communicate online. The first consideration is the HTTP protocol because all J2ME phones support this, and we certainly want to compatible users as possible. Moreover, the HTTP protocol package is very high, no need to consider thread, synchronous, state management, connection pool, but the HTTP protocol has two uncomfortable places: ◇ Agreement is incapable, this problem has been plagued many people many times. The solution I have considered is to transform the HTTP protocol. Do not close Socket after the completion of the data transfer, but this workload is very large, in the project cycle, basically Mission Impossible, not considered. Then, customers can only request data to the server by polling. ◇ The network traffic is too large. For this project, it is just an instruction between the network, but every pass is plus a bunch of unused HTTP Head, plus the client needs to be polled, this traffic is horrible for mobile phones. Simple test, according to the 0.03 yuan / K GPRS network cost calculation, a group of cards actually consume more than 1 yuan (polling per second), which is unacceptable. Maybe we can use the traffic fee of the monthly fee, but this topic has nothing to do with technology.

The above problems have led us to Socket, which means that we will have no web environment, and many things must be implemented by themselves: thread management, customer status monitoring, object pool, console ..........

Network part intends to implement Java NIO, which is a new network monitoring method, and event-based asynchronous communication can improve performance. After each client is connected, there will be a separate SocketChannel with it, which exists in the entire survival cycle of the user. If the user is disconnected, the server will get -1 and will throw the Connection RESET exception. By capturing these two features, you can clean the relevant resources after the user unexpectedly disconnected. Since NIO is asynchronous communication, there is no complex thread management. Next: About Communication Agreement

转载请注明原文地址:https://www.9cbs.com/read-68919.html

New Post(0)