P. 1


|Views: 7|Likes:
Published by Frank Elijorde

More info:

Published by: Frank Elijorde on Oct 24, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





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.

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

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->