In the late nineties I was working for an online video game company where I spent my days writing Unix Berkley Sockets and Windows WinSock code. My task was to enable video game clients to communicate with a game server. When I had the opportunity to write some Java socket code, I was amazed by Java's streamlined and straightforward approach to network programming. This is no surprise because Java was originally designed to enable smart devices to communicate with one another, which translated very well to desktop and server applications.
In 1996, JavaWorld published "Sockets programming in Java: A tutorial." Written by Qusay H. Mahmoud, the article presents an overview of the Java model for socket programming. While a few things have changed in the 18 years since, Mahmoud's article is still a classic introduction to Java socket programming in networked systems. I'll build on that work here by first presenting a simple client-server example that demonstrates the humble beginnings of Java I/O. The example will demonstrate features from both the original java.io package and NIO, the new, non-blocking I/O (java.nio) APIs introduced in Java 1.4. My final example will leverage some of the NIO.2 features introduced in Java 7.