Java Technology Home Page
Help pagesA-Z Index

The Source for Java Technology

 

Downloads, APIs, Documentation
Java Developer Connection
Docs, Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide

  Printer-friendly
version

  

JAVATM TECHNOLOGY IN THE MULTIPLAYER INTERNET GAME ARENA

by Dana Nourie

March 29, 2002 -- Market researcher IDC predicts a total U.S. revenue from online gaming will increase almost 50% annually over the next few years, from $210 million in 2001 to $1.8 billion in 2005.

How those numbers pan out in reality has yet to be seen, but one thing is certain: The JavaTM platform has what it takes to produce online games in the hands of creative developers as demonstrated in this year's JavaOneSM conference session, "Building High Performance Multiplayer Internet Games With Java Technology."

Why use the Java platform for online gaming?

"'Write Once, Run AnywhereTM' is essential for online gaming," says John G. Miller Jr., president of Digital Gamers. "In console gaming, massive revenue is lost every time a new console comes out. We don't suffer this revenue loss with online gaming, and the Java platform has the API we need for both the client side and the back end."

What You Need

The following Java technologies can be used specifically for online gaming:

  • Java 2 Platform, Standard Edition (J2SETM) version 1.4 contains performance improvements over 1.3 and specific classes that accelerate graphics, such as VolatileImage and BufferedStrategy.
  • Java 2DTM also is improved in 1.4 from 1.3.
  • Java 3DTM.
  • Java I/O, specifically java.nio, is new in version 1.4.
  • Java Sound.

Small games can run from browser-based applets while larger games can be packaged on CDs, both of which can connect to a network so that players can enter a multiplayer environment. This environment is not without problems, however.

Special Gaming Challenges

Network and server-side pose challenges:

  • Bandwidth -- You need to be able to handle the heavy traffic.
  • Reliability -- Lost or garbled packets must be prevented.
  • Delivery -- Disordered or delayed packets can cause problems in many areas.
  • Synchronization -- Keep multiple clients in sync with each other.
  • Users must see the same thing at the same time.
  • Security -- Prevent hackers from attempting to scramble packets or corrupt data.
  • Client management -- Make decisions on whether to separate or share connections and threads for clients.
  • Persistence and object management -- Decide whether to cache objects or not to cache them.

To minimize these problems, send as little data as possible over the network and store as much of the virtual world as possible on the client's machine. Send substates of objects rather than entire objects. Thereafter, you only need to send messages of changes that have occurred for any particular object.

Create your own sequenced protocol on top of UDP. UDP packets are delivered just like IP packets: connection-less datagrams that may be discarded before reaching their targets. UDP is useful when TCP would be too complex, too slow, or just unnecessary. A sequence number is tracked by the client to detect earlier messages. Sequence numbers may be used to detect and ignore superseded messages as well.

Create separate command and delta network channels:

  • TCP for command channel makes up for IP's deficiencies by providing reliable stream-oriented connections that hide most of IP's shortcomings.
  • Two-way communication on the command channel ensures you get messages from the client to the server, then the server can send a message back to the client for updates.
  • UDP for a data channel.

User Interface-Responsive Challenges

Equally important is working with user interface issues (UI) and challenges. The main aspect here is responsiveness in the UI. Users must see avatars or characters move about in real time or at least in what appears to be very close to real time.

Warping is one of the most common UI problems. For instance, a character may be walking along, and the message for him to stop gets lost. The character continues to move, walking into a wall. So the user sends the message to back up to the right. Suddenly, the previous message for the character to stop at the previously specified point comes through; the image suddenly appears back where it should have stopped; then the message arrives that the user had backed the character to the right, warping the character yet again.

You must prevent this kind of UI problem for an enjoyable gaming experience.

Possible UI blockers are:

  • Disk access
  • Network I/O
  • Animation, rendering of the UI itself
  • Sound

Take advantage of the Java thread model. Multithreading works well in a multiplayer environment. Place these blockers on separate threads from the UI. Perform animation with java.util.TimerTask and

javax.swing.ActionListener.
Use wait() and notify() in audio threads for MIDI or sound samples to be placed in a queue.

Use the new I/O in J2SE 1.4 for file network reads. New I/O, java.nio provides a clean mechanism for interrupting blocking socket operations and for blocking reads on the SocketChannel in the thread managing of the SocketChannel.

A socket channel is created by invoking one of the open methods of this class. A newly created socket channel is open but not yet connected. An attempt to invoke an I/O operation upon an unconnected channel causes a NotYetConnectedException to be thrown. A socket channel can be connected by invoking its connect method; once connected, a socket channel remains connected until it is closed. Whether or not a socket channel is connected may be determined by invoking its isConnected method.

Socket channels support nonblocking connection: A socket channel may be created, and the process of establishing the link to the remote socket may be initiated by way of the connect method for later completion by the finishConnect method. Whether or not a connection operation is in progress may be determined by invoking the isConnectionPending method.

For fast graphics rendering, use BufferedStrategy and VolatileImage classes in 1.4, which take advantage of hardware for accelerated graphics.

The BufferStrategy class represents the mechanism to organize complex memory on a particular Canvas or Window. Hardware and software limitations determine whether and how a particular buffer strategy can be implemented. These limitations are detectible through the capabilities of the GraphicsConfiguration used when creating the Canvas or Window.

Because of the potential for hardware acceleration, a VolatileImage object can have significant performance benefits on some platforms. The drawing surface of an image, the memory where the image contents actually reside, can be lost or invalidated, causing the contents of that memory to disappear. The drawing surface then needs to be restored and the contents of that surface to be re-rendered. VolatileImage provides an interface for allowing the user to detect these problems and fix them when they occur.

Finally, set up full-screen mode and use page flipping. Once an application is in full-screen exclusive mode, it may be able to take advantage of actively setting the display mode. A display mode -- java.awt.DisplayMode -- is composed of the size, such as width and height of the monitor in pixels, bit depth, and refresh rate.

When a page flip occurs, the pointer to the old back buffer now points to the primary surface, and the pointer to the old primary surface now points to the back buffer memory. This sets you up automatically for the next draw operation.

Java technology, especially with the big release of J2SE 1.4, provides the API necessary to build solid virtual worlds where gamers can play against each other in a multiplayer environment.

end.

See Also

Digital Gamers
(http://www.digigamers.com/)

JavaGaming.Org
(http://www.javagaming.org/)

Creating a Threaded Slide Show Applet
(http://java.sun.com/jdc/technicalArticles/Threads/applet/index.html)

Java 3DTM API Tutorial
(http://developer.java.sun.com/developer/onlineTraining/java3d/)

3-D User Interfaces with Java 3DTM
(http://developer.java.sun.com/developer/Books/Java3D/)

Java 3DTM API
(http://java.sun.com/products/java-media/3D/)

Frequently Asked Questions About Java 2DTM
(http://java.sun.com/products/java-media/2D/forDevelopers/java2dfaq.html)

Full-Screen Exclusive Mode
(http://java.sun.com/docs/books/tutorial/extra/fullscreen/exclusivemode.html)

Double Buffering and Page Flipping
(http://java.sun.com/docs/books/tutorial/extra/fullscreen/doublebuf.html)

Download J2SETM
(http://java.sun.com/j2se/)




Reader Survey
I found this article...   very worth reading    worth reading    not worth reading
Comments only, please. Questions can be answered in the Help Pages
 
Recent Features


Products & APIs - Developer Connection - Docs & Training - Support
Community Discussion - Industry News - Solutions Marketplace - Case Studies
Glossary - Help Pages

For answers to common questions and further contact
information please see the java.sun.com Help Pages.
Sun Microsystems, Inc.
Copyright © 1995-2002 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.