javax.nio

The one-thread-per-socket approach works well for small numbers of connections and greatly simplifies the code for those cases. Some situations, such as Internet game servers, however, require you to handle hundreds or thousands of connections.

The java.io streams are also simple to use but require data to be copied multiple times before it reaches you. This overhead is particularly noticeable in heavy networking applications that need to do multiple layers of custom packet protocols. Each of these layers typically requires the data to be prepended with a protocol-specific header and each of these prepends ends up meaning another copy of the data.

The javax.nio package contains classes that address both of these issues. Because java.nio isn’t really necessary for typical LAN games, it won’t be covered in this chapter, but a good reference for learning more about NIO is http://java.sun.com/j2se/1.4.2/docs/guide/nio.



Practical Java Game Programming
Practical Java Game Programming (Charles River Media Game Development)
ISBN: 1584503262
EAN: 2147483647
Year: 2003
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net