an abstraction for network connections that first
appeared on Unix systems in the mid-1970s. In the
intervening 25 years, the socket interface has
become a cornerstone of distributed programming.
Java supports sockets with the classes and
interfaces defined in the
contains two classes that are the core Java
classes used when reliable communication between
two different processes is necessary:
ServerSocket. They have
the following roles:
a single connection between two known, established
processes. In order to exchange information, both
programs must have created instances of
initial connections between a client and a server.
That is, when a client connects to a server using
an instance of
Socket, it first communicates with
immediately creates a delegate (ordinary) socket
and assigns this new socket to the client. This
process, by which a socket-to-socket connection is
established, is often called
Another way to think of this: sockets are analogous to phone lines; ServerSockets are analogous to operators who manually create connections between two phones.
In order to create a socket connection to a remote process, you must know two pieces of information: the address of the remote machine and the port the socket uses.
Addresses are absolute—they specify a single computer somewhere on your ...