Back Contents Next

The java.net Package

The java.net package provides classes that allow programs to exchange data across a network. The programs do not have to be running on the same machine and indeed the machines can be located thousands of miles from each other. The data exchange model used by Java is based on the BSD UNIX socket library model.

 

There are two mechanisms, or protocols, for exchanging data. The first mechanism for transferring data between a two programs is called the connectionless protocol. With this protocol, a packet of information is sent without any guarantee that it will be delivered to the recipient, and without any way for the sender to determine whether or not it has arrived. The second basic mechanism for transfering data between a client and server is called the connection-oriented protocol. In this case, a connection between the client and server socket is established before data is transmitted. The connectionless protocol has a performance advantage over the connection-oriented protocol, however there is less certainty that the data will arrive as it was intended.

 

The java.net package also contains classes that implement and support connections to resources using Uniform Resource Locators or URLs.

 

The java.net class hierarchy is shown in the figure below.

 

 

In this Chapter we will cover:

5.1 Connectionless Protocol Classes

5.1.1 DatagramPacket Class

5.1.2 DatagramSocket Class

5.1.3 MulticastSocket Class

5.2 Connection-Oriented Protocol Classes

5.2.1 ServerSocket Class

5.2.2 Socket Class

5.3 Miscellaneous Classes

5.3.1 InetAddress Class

5.4 URL Classes

5.4.1 URL class

5.4.2 URLConnection Class

5.4.3 HttpURLConnection Class

5.4.5 URLDecoder Class

5.4.6 URLEncoder Class

 


Back Contents Next
©1999 Wrox Press Limited, US and UK.
home | tutorial | questions | test 1