Java 2 Networking

Book Cover Author: Justin Couch
Publisher: McGraw-Hill
Date: Jan 1999
ISBN: 0071348131
Purchase: Amazon

News: 18/8/99 JSDT 2.0 EA1 is now available. I'm struggling to keep up with the changes to the code and the book at the moment due to some impending work deadlines. I'm hoping to get the 1.5 updates complete shortly, but I can't promise anything unfortunately. I may skip these and head directly to the 2.0 stuff.

4/7/99 - Updates for JSDT 1.5 and other chapters are online. Although not yet complete, the pages are getting there. These should be complete within the next week or two.

20/5/99 - JSDT 1.5 is now available for free! The old 1.4 version was a for-sale product, but Sun have changed their minds again and made it free for all use - even commerical. I'm now going to pass over all the JSDT code and update it to 1.5. Stay tuned.

Following a couple of requests, I've put the code online from the CD. At this stage, I've just put a dump of the entire CD that I submitted for the book (I still haven't received my own copies yet). Its pretty hefty at around 7MB, so only if you dare :) I'll get around to splitting it all up as soon as possible.

Download: FTP, HTTP.

  Return to top
Well, I've finally broken out of the VRML market with this book. This pure Java book is all about writing networked applications in java. Not just those trivial toy apps, but something real and serious. Almost all of the book is based around my experiences over the last 18 months of professional java development of a distributed mission-critical application (as in - people die if it fails).

It is aimed squarely at Java 2. You won't find any Java 1.1 and "and now here's how it's done in Java 2" sections. I cover all aspects of Java networking and related topics such as threading and serialisation from the aspect of usefulness to networking.

Far from being an API bible, this book aims to introduce you to the essential parts that you need to know in order to do your job properly. Part of this is knowing the strengths and weaknesses of every option available to you. Also, it seeks to avoid as much of your pain as possible by showing all of the common pitfalls that besiege a networking novice. That is, we take you through the development of the code just as if we were writing it for the first time. The code makes mistakes, shows you where they are and then how to correct them. Thus when (not if) you make those mistakes again at a later time you'll be at least prepared to know how to deal with them.

  Return to top

Development Notes

While the book was being written, I like almost everyone else, assumed that the next version was going to be called Java 2. I'd written most of the book during the period when it was beta 4 while a small bit drifted into the RC1 release. During this time everything was written assuming 2. I'd carefully gone through and checked to pick up bits where it had changed through various releases so that it was as up to date as possible.

Work came back for review and final edit just after RC2 was released in late November (1998). Assuming that not much had changed we went with this - particularly for the first few chapters. Luckily, the final release came out just before I handed in the last few chapters (not including the JSDT stuff). Having handed everything in, then came the official announcement and the name change - DOH! By this stage, nothing had hit the presses and the editor asked if I wanted to change the name to indicate Java 2. Quickly tossing up the options I decided against it because the cover would say Java 2 but we couldn't guarantee that we'd catch every mention in the body of the book. So the book, AFAIK, was to be titled Real World Java 1.2 Networking. About a month later, I receive an email asking about the relation between my Java 2 networking book and the Real World book. After some investigation, it seems as though the publishers changed their mind and changed the title and made the reference changes in the book. The only minor hiccup in this is that the code still has the rwjn prefix to all the packages. Oh well...

So to answer any early queries - Yes, the book is fully Java 2 compliant, it is not some beta java version based. If there are any slip ups, I'll let you know through this page. Check back every now and again for updates, typos etc.

  Return to top

Updates

In order to keep up with my promises, I've put a bunch of updates online.

I just read a review over on Amazon. Its funny, but that is the first time I have ever been accused of lacking character! Normally its the other way around - I've got too much of it. Well, at least my books aren't all like the Java Bible that I've just helped to update. There I was weeding out odd tales about a guy drinking Coffee and other really strange things. I suppose if you want a beginners book that appeals to the idiot user then fine, my books are not for you. Almost 3 years after I wrote it, Late Night VRML is still regarded as a bible for VRML, even without having done an update. In private email, I have yet to receive one email that has any negative comments so I can't be doing too bad. Can't please everyone I s'pose....

JSDT 1.5

JSDT version 1.5 has now been officially released. The best news about this is that it is now FREE. The eval edition on the book CD can be tossed in favour of the new lib. Head over and download a new copy then check out the update pages for changes to the code and new notes.

Image Loader

I have a number of updates to the image loader code soon to make it through the works. I could push the source out the door now, but I want to include a compiled version of the native code for Win32. Unfortunately that means having to purchase a copy of VC++ 6.0. I hate having to give MS money, but I don't have access to a compiler at work (we've only got 5.0 which runs the native code at about half the speed of 6.0).

URN libraries

Version 0.7 is almost ready. We've been hammering on this pretty hard at work recently but have a few more tests to go. This should be the most heavily tested library I've yet released. There are only a few more features that I want to add - namely authentication handling.

News

Well, the strangest things happen at JavaOne. Not just once, but a number of times, on different occasions, it was mentioned that rmiregistry should not be used in a production environment. Solution - use JINI's lookup locator classes instead. Hmmm. Doesn't have anything to do with this big JINI push yet does it?

Kestrel, which is Sun's code name for the next release of Java (aka JDK 1.3) has already started work. There are a number of really interesting things coming along to allow better networking. One of these is the possible inclusion of URNs into the core libs, and also the asynchronous I/O classes becoming available.

Code

Download:
Original FTP HTTP.
JSDT Chapters

  Return to top

Book Outline

The book starts by assuming that you are already a reasonably competent with Java as a language. At the start there is the usual introductory chapter. This covers a little of the history of Java 2.

Introducing Java Networking Concepts

For those that aren't too familiar with networking and want to know more, then you can read the second chapter, where I introduce networking in not-too technical terms. Having survived an Elec Eng degree I know just how nasty networking terminology can get. The aim is to describe it in layman's terms using examples from the real world that you are already familiar with.

After introducing the concepts of where different standards fit in, we move slowly up the chain to deal purely with IP based networking. At this level we discuss the roles of the various standards and standards bodies that exist and how they work in the big picture. Also, it introduces the basic standards that effect a large majority of your networking applications such as MIME types, Various TCP protocols and URLs

Having established all the basic theoretical concepts, the Java interpretation of these is introduced. All of the important classes are kept in the java.net package so we do a wide but shallow look at every class and their capabilities in the third chapter.

Establishing Background Knowledge

With some basic understanding of what a network is and does, and how java represents it, we cover a fair amount of background knowledge. While knowing everything about the networking APIs may be useful, the real value comes when you know how to combine it with other parts of the Java APIs. During the course of the book, we look at two different areas: multi-threading and serialisation.

Multi-threading is absolutely essential to any non-trivial networking app. However, in this treatment, we look at it from the perspective of how it helps to write networking applications. That is, we don't go into heavy theory OS implementations and all that sort of stuff. After all, you're going to be using threading pretty much through the rest of the book.

Serialisation is also important to many aspects of networked, as well as non-networked apps. Serialisation is at the core of RMI and many other future technologies coming out in the Java world - such as JINI.

Writing Standard Networking Apps

With a good grounding in the fundamental concepts and supporting technologies, the book delves into standard network programming. Writing TCP and UDP based applications should be the bread and butter of any network coder. Knowing how to use them effectively is an important part.

In this part of the book, we go it a little slow. A simple introduction to all of the requirements of network programming and surrounding code. Unlike the later parts, we don't dive heavily into all of the little options that we could use to improve the code. We stick very much to just the core socket programming information - creating connections, sending and receiving information (both binary and text), and tearing them down again. First establish good coding habits, then learn to make it dance.

Expanding on the Basics

Feeling comfortable with basic networking capabilities, we look at the various APIs built on top of just a basic socket connection. This is where we really start to earn that Masters title. The first of the expanded section covers RMI. Once that fits into your toolkit, we look at expanding the basic RMI using activation, custom sockets and many other cool tricks. Having been saturated with RMI we take a big step sideways and look at Java's capability to build customised URL handling.

RMI, as a basic system, is still relatively complex to set up well and make it worth the trouble. Simple things like dealing with Java's new security model up to complex issues like how to optomise RMI to make it fly are all covered. While doing this, you are given a pretty thorough under the hood look at how RMI is implemented. Why is this necessary? Well, in the real world, making RMI acceptable to end users (that is, making it quick), depends a lot on you knowing everything about how something is implemented. If you don't want to know how things work under the hood, then Java isn't the language for you because this knowledge is essential to making anything in Java run with decent performance. (perhaps try Visual Basic otherwise...)

Once RMI fits like a glove, we come along and disturb you again by throwing a whole heap more at you. Activation, new to RMI for Java 2, is a very worthwhile tool, but it also costs you a lot in other things, unless of course you know your way around its internals. Again, we build the background information needed to make your job easier when the PHB types tell you to change the design a week before something is due. Oops, need encrypted links, no problem we can do that for you too in RMI. It's all there.

One of the least understood, but one of the most useful part of Java has to be the URL classes. I have never seen a decent treatment of them in any Java text. They seem to be some black magic thing that programmers don't approach for fear of upsetting the mystical beast. We remove the mysticism and show you how really simple it is and what this can really do. We build customised protocol handlers for a Telnet application and an image loader for PNG images (all code included!).

Building Collaborative Applications

These days of the Internet, the marketing types are all about building communities. One of the core requirements of a community is the collaboration on something. Things like ICQ are built around knowing who is on and off the web and then chatting with them. At a higher level, being part of a video conference embodies the same underlying concepts of collaboration. In this section we introduce part of the Java Media Framework called JSDT (Java Shared Data Toolkit).

JSDT is one of those great time saving APIs that really finds itself used in all sorts of weird places. Its great for building a quick chat application, but building a lock-em-out, no-holds-barred secure conferencing facility takes only a few minutes longer to code. If you're in any doubt, we build a full application in the finale to the book. There's almost 100 classes just for this one app.

  Return to top

Table Of Contents

Chapter 1: Introduction
Chapter 2: Internet Networking Concepts
Chapter 3: The java.net Package Chapter 4: Threading For Networking
Chapter 5: Writing TCP Communications
Chapter 6: Writing UDP and Multicast Communications
Chapter 7: Object Serialisation
Chapter 8: Remote Method Invocation (RMI)
Chapter 9: Advanced RMI
Chapter 10: Customised URL Handling
Chapter 11: The Java Shared Data Toolkit
Chapter 12: Advanced JSDT - Gaining Control of the Situation
Chapter 13: Sharing Your Thoughts
Online Updates

  Return to top

[ Homepage ][ VRML ][ Linux ][ Books ][ Java ][ About ]