J2ME Multiplayer Game notes (note Class)

Source: Internet
Author: User
Tags data structures include interface range resource socket
Note One MIDP communication technology





1. HTTP:





when the real phone in the network is configured for HTTP streaming midlet, do not try to send only one small piece of data at a time: you will not receive anything until you have finished sending all the data.





when sending an HTTP response from a server to be deferred to an event, developing a connection in a mobile network can be expensive and often timed out to the midrange, which is more likely to occur than on the Internet.





mobile phones typically do not have the resources to support multiple open HTTP connections. The cost of data structures and caching is very high.














HTTP Method





get: is used to request a static resource from the server, and the same resource response is repeated for a getting request. The GET request provides only the URL of the resource, excluding any message bodies.





post: Used to request a dynamic resource to the server (such as a round in the game), repeating a POST request will get a different resource response. The post response also includes a message body with service response data, which is a common method of MIDlet.





HTTP responses from a server may contain status codes such as success (2XX), redirects (3xx), or errors (4xx, 5xx). The code needs to be handled by the HTTP client.














HTTP message body




The information sent by
is only a stream of bytes, which can be encoded, including:





text; image files (at least support for PNG decoding); XML; Other user-defined data structures.














HTTP Session




The
server tracks a series of successive requests initiated by MIDlet as an HTTP session, and because HTTP itself is stateless, session management must be implemented on top of the HTTP protocol layer.





method One: various session cookies.





method Two: URL rewrite.





because cookies have other uses, the complete midlet of the processing session cookie is complex, and the URL is much simpler.














HTTP Server





has a variety of options including Java servlet, JSP, ASP, asp.net, CGI script.























2. TCP:





http on the Internet is usually implemented as TCP, and the TCP connection endpoint is a socket socket. MIDP 1.0 does not include support for TCP, MIDP 2.0 provides support for TCP, and manufacturers can choose whether or not to include this support.





3. UDP:




When
uses UDP, the datagram (datagram) sent between the two communicating devices is often referred to as the packet (data packet), MIDP 1.0 does not include support for UDP, and MIDP 2.0 provides support for UDP. Manufacturers can choose whether to include this support themselves. When implemented on packet switching protocols such as GPRS, packet delivery is generally not required to be more than one per second, taking into account the response time of the mobile network, and note the packet size.














4. Serial cable





MIDP 2.0 implements support through interface serialportconnection.














5. IR





MIDP 2.0 implements support through interface serialportconnection.














6. Bluetooth (MIDP optional Packet communication technology)





A short-range wireless technology, supporting about 10 meters range of up to 8 devices to communicate together, response time is short, very suitable for multiplayer games (due to Bluetooth over the transmission in all directions, do not have to pair with each other).














7. SMS Short Message Service





SMS (Short message Service) can send text messages or binary data, which is a "store-and-forward" technique. The message is saved in the queue through a short Message Service center (SMSC) and forwarded later.























8. MMS Multimedia Messaging Service





is an upgraded version of SMS that allows you to divide a message into several parts, including text, images, sounds, and videos, and is also a "store-and-forward" technology. MMS implementations use SMS and HTTP in combination.














Two game server technology





http and HTTPS





on the server side, you can use any technology that is typically used for HTTP servers, such as static Web pages, CGI, ASP, Java servlet, and JavaServer page (JSP). The common choice for Java programmers is the Java servlet.








three game types and related considerations





Multiplayer single player & Round game:





This kind of game characteristic is the player turns to play, does not use the network, also will not be limited by the network extension world.














round robin Game & simultaneous action games:





when using MIDP 1.0, you can choose HTTP, but HTTP has a significant disadvantage that the game server is unable to tell the MIDP client: Now it's your turn, so the client has to test and ask the game server regularly: Is it my turn, You should consider providing a scenario that interrupts the wait and starts the next query immediately.





MIDP 2.0,tcp may be the best option, and it is important that the server notifies him immediately when it is time to turn to a player, so UDP may not be appropriate. In addition, the additional latency that TCP may cause in a round robin is not a problem.














"Play at any time" type of game:





If the game involves real-time action, the delay of HTTP will appear too serious. When using MIDP 2.0, you should consider UDP, TCP, or a combination of both. The delay of the mobile network is too great for fast, real-time multiplayer interactive games.














more than four multiplayer games common characteristics





Permanent user account





Game Hall (Lobby)





High score Table





Conversations between players





Show delay ...











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.