On the application of instant strategy game J2ME

Source: Internet
Author: User
Tags socket dedicated server client
Strategic--------------------------------------------------------------------------------
"Star", "Warcraft", "civilization" ... These are the familiar names of PC gamers, and it can be said that the strategic games represented by these games are typical of PC games, and that the players in the strategy game are the most loyal players in many PC game types. Strategic game is divided into round and immediate strategy, two kinds of strategic games have a large number of players, and the latter because of intense gameplay gradually overwhelm the round strategy game, in recent years, has been in the strategic game dominated.


The topic of developing online instant strategy games on the J2ME platform is a myth that most J2ME developers today hear. Instant strategy game Name "Instant" two word determines the complex operation and data interaction, stable and fast network connection requirements, huge resources and mapping tasks, we all know J2ME equipment resources and performance are extremely limited, the existing GPRS network industry is not satisfactory ... All this seems to be an insurmountable difficulty in developing online instant strategy games on J2ME.

The difficulties are really in front of us, but the huge potential instant strategy players in China's 300 million mobile phone users are prompting us to overcome these difficulties, as long as we have a chance to find a way to cross these barriers. How can you implement the online instant strategy game on your mobile phone?

From the performance and user volume considerations, we choose Nokia's 60 series as the initial development platform.
We do not consider using the HTTP protocol, although it is a common protocol in the J2ME device, but its relative low efficiency of the socket and itself is connectionless protocol determines it is not suitable for the real-time strategy of this game form. From the table above, you can see that the time to establish a connection is higher than the data transfer time after the connection, the HTTP protocol needs to spend a lot of extra overhead on establishing the connection, and the HTTP average data transfer time is much higher than the socket. We tested most of the 60 models (7650, 3650, 3660, 6600, N-gage, N-gage QD), and all tested models supported sockets.

As can be seen from the table above, the average time between the socket connection data is 1 ~ 2 seconds, which may be enough for the round strategy game, but it is still too long for the instant strategy game. Is there any way to drastically compress the data transfer time?

We can consider it from the server and packet protocol.

The above test server is written in Serverlet, and Serverlet is built on the Web server, then the data contained in the server response and processing time can not be ignored, in order to get faster response and processing speed, We have to redesign and build a dedicated server for the game. The size of the packets transferred is also a key factor in the speed. At ordinary times we develop J2ME network applications, accustomed to using text flow to transfer data, because most of the application server is based on Web server, and the use of text presentation information is very intuitive and easy to Server processing, but for the J2ME platform and GPRS network, There is no compressed text or a bit of waste.

Simply consider the game server: a host should be able to support 100 to 200 players online at the same time; for ease of configuration, server applications should be cross-platform and clients are J2ME, so server's development environment Java is preferred; Java 1.4 after Java Asynchronous communication function, performance can also meet our requirements.

Because the server must be written by ourselves, it is not necessary to use a text encoding protocol instead of a byte stream encoding. A simple estimate, the same information, the text and byte encoding data size ratio is greater than 4:1, and the data is originally based on numbers, eliminating the large cost of text conversion. Smaller data also brings faster speeds, and it also saves users a huge amount of expensive GPRS traffic.

After taking the above measures, we tested the response time of the data transmission again, on average less than 1 seconds! Perhaps in many people's view, this time is still too long, can not meet the real-time requirements, but it should be known, absolute real-time is impossible to achieve, as long as the planning and development of the use of some reasonable strategy, this is less than 1 seconds delay is completely good to cover up.

Typical PC instant strategy games such as "Star", in the local area network does not need a server in wartime, one or more of the clients in the game as the role of the server, even on the network, the Battle network server is only the work of community management. Implementations on a mobile phone cannot take this structure: first of all, through the GPRS network, two mobile phones can not be directly connected (do not rule out Bluetooth or infrared interconnection, this is not within the scope of our discussion), only through the server relay; In addition, the mobile phone's computational ability is limited, in order to play a good operation, Many of the operations must be transferred to a more resource-rich server side, which, in general CS architecture, makes it possible for the client to share the work of the server so that the server can support more client practices, and it also embodies the particularity of the J2ME network application:

Just a little bit more about the architecture of the whole system:


The server is divided into five types: connecting server, lobby server, game logical server, user Management Server and log server. Depending on the number of users, if the number is small, all servers can be placed in a host; with the increase of users, each server can be moved to different hosts, by adjusting the number of server hosts to achieve a balanced load.



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.