16.2 InetAddress The InetAddress is Java's representation of an IP address.

In the case of InetAddress, the three methods getLocalHost(), getByName(), and getAllByName() can be used to create instances of InetAddress. The getLocalHost( ) method simply returns the InetAddress object that represents the local host. The getByName( ) method returns an InetAddress for a host name passed to it. If these methods are unable to resolve the host name, they throw an UnknownHostException. On the Internet, it is common for a single name to be used to represent several machines. The getAllByName( ) method returns an array of InetAddresses that represent all of the addresses that a particular name resolves to. 16.3 URL The java.net.URL class represents a URL. The heart of the class are the methods that allow you to get an InputStream from a URL so you can read data from a server. The java.net.URL class has five methods to split a URL into its component parts. These are:
public public public public public String String int String String getProtocol() getHost() getPort() getFile() getRef()

The openStream() method opens a connection to the server specified in the URL and returns an InputStream fed by the data from that connection. This allows you to download data from the server. 16.4 Sockets There are four fundamental operations a socket performs. These are: 1. 2. 3. 4. Connect to a remote machine Send data Receive data Close the connection

A socket may not be connected to more than one host at a time. The socket represents a reliable connection for the transmission of data between two hosts.

6 Chat //203.234.104/chat/clientchat. provides unguaranteed.5 UDP The User Datagram Protocol. The same DatagramSocket can both and receive. The DatagramPacket class is a wrapper for an array of bytes from which data will be sent or into which data will be received. java. A DatagramSocket is used to send and receive DatagramPackets. provides reliable. connection-oriented transmission of data. By contrast.48. The DatagramSocket class is a connection to a port that does the sending and receiving. UDP for short. TCP. connectionless transmission of data across an IP network.net.16.net. 16. there is no distinction between a UDP socket and a UDP server socket. Unlike TCP sockets.html .DatagramPacket.DatagramSocket and java. It also contains the address and port to which the packet will be sent. Java's support for UDP is contained in two classes.