The java.net package provides a powerful and flexible infrastructure for networking. This introduction describes the most commonly used classes in brief. Note that as of Java 1.4, the New I/O API of java.nio and java.nio.channels can be used for high-performance nonblocking networking. See also the javax.net.ssl package for classes for secure networking using SSL. The URL class represents an Internet uniform resource locator (URL). It provides a very simple interface to networking: the object referred to by the URL can be downloaded with a single call, or streams may be opened to read from or write to the object. At a slightly more complex level, a URLConnection object can be obtained from a given URL object. The URLConnection class provides additional methods that allow you to work with URLs in more sophisticated ways. Java 1.4 introduced the URI class; it provides a powerful API for manipulating URI and URL strings but does not have any networking capabilities itself. Java 5.0 defines APIs for defining and registering cache, cookie, and proxy handlers to be used by built-in protocol handlers when network resources are requested through the URL class. See RequestCache , CookieHandler , ProxySelector , and Proxy . If you want to do more than simply download an object referenced by a URL, you can do your own networking with the Socket class. This class allows you to connect to a specified port on a specified Internet host and read and write data using the InputStream and OutputStream classes of the java.io package. If you want to implement a server to accept connections from clients , you can use the related ServerSocket class. Both Socket and ServerSocket use the InetAddress address class, which represents an Internet address. Added in Java 1.4, Inet4Address and Inet6Address are subclasses that represent the addresses used by version 4 and version 6 of the IP protocol. Java 1.4 also introduced the SocketAddress class as a high-level representation of a network address that is not tied to a specific networking protocol. An IP-specific InetSocketAddress subclass encapsulates an InetAddress and a port number. The java.net package allows you to do low-level networking with DatagramPacket objects, which may be sent and received over the network through a DatagramSocket object. MulticastSocket extends DatagramSocket to support multicast networking. Interfacespublic interface ContentHandlerFactory ; public interface DatagramSocketImplFactory ; public interface FileNameMap ; public interface SocketImplFactory ; public interface SocketOptions ; public interface URLStreamHandlerFactory ; Enumerated Typespublic enum Authenticator.RequestorType ; public enum Proxy.Type ; Classespublic abstract class Authenticator ; public abstract class CacheRequest ; public abstract class CacheResponse ; public abstract class SecureCacheResponse extends CacheResponse; public abstract class ContentHandler ; public abstract class CookieHandler ; public final class DatagramPacket ; public class DatagramSocket ; public class MulticastSocket extends DatagramSocket; public abstract class DatagramSocketImpl implements SocketOptions; public class InetAddress implements Serializable; public final class Inet4Address extends InetAddress; public final class Inet6Address extends InetAddress; public final class NetPermission extends java.security.BasicPermission; public final class NetworkInterface ; public final class PasswordAuthentication ; public class Proxy ; public abstract class ProxySelector ; public abstract class ResponseCache ; public class ServerSocket ; public class Socket ; public abstract class SocketAddress implements Serializable; public class InetSocketAddress extends SocketAddress; public abstract class SocketImpl implements SocketOptions; public final class SocketPermission extends java.security.Permission implements Serializable; public final class URI implements Comparable<URI>, Serializable; public final class URL implements Serializable; public class URLClassLoader extends java.security.SecureClassLoader; public abstract class URLConnection ; public abstract class HttpURLConnection extends URLConnection; public abstract class JarURLConnection extends URLConnection; public class URLDecoder ; public class URLEncoder ; public abstract class URLStreamHandler ; Exceptionspublic class HttpRetryException extends java.io.IOException; public class MalformedURLException extends java.io.IOException; public class ProtocolException extends java.io.IOException; public class SocketException extends java.io.IOException; public class BindException extends SocketException; public class ConnectException extends SocketException; public class NoRouteToHostException extends SocketException; public class PortUnreachableException extends SocketException; public class SocketTimeoutException extends java.io.InterruptedIOException; public class UnknownHostException extends java.io.IOException; public class UnknownServiceException extends java.io.IOException; public class URISyntaxException extends Exception; |