Java Reference
In-Depth Information
public static void main ( String [] args ) {
try {
int port = Integer . parseInt ( args [ 0 ]);
ServerSocket ss = new ServerSocket ( port );
for (;;) {
Socket client = ss . accept ();
HTTPHandler hndlr = new HTTPHandler ( client );
new Thread ( hndlr ). start ();
} catch ( Exception e ) {
// Handle exception
When designing a protocol for applications to communicate over TCP, there's a sim‐
ple and profound network architecture principle, known as Postel's Law (after Jon
Postel, one of the fathers of the Internet) that should always be kept in mind. It is
sometimes stated as follows: “Be strict about what you send, and liberal about what
you will accept.” This simple principle means that communication can remain
broadly possible in a network system, even in the event of quite imperfect imple‐
Postel's Law, when combined with the general principle that the protocol should be
as simple as possible (sometimes called the KISS principle), will make the develo‐
per's job of implementing TCP-based communication much easier than it otherwise
would be.
Below TCP is the Internet's general-purpose haulage protocol—the Internet Proto‐
col (IP) itself.
IP is the “lowest common denominator” transport, and provides a useful abstrac‐
tion over the physical network technologies that are used to actually move bytes
from A to B.
Unlike TCP, delivery of an IP packet is not guaranteed, and a packet can be dropped
by any overloaded system along the path. IP packets do have a destination, but usu‐
ally no routing data—it's the responsiblity of the (possibly many different) physical
transports along the route to actually deliver the data.
It is possible to create “datagram” services in Java that are based around single IP
packets (or those with a UDP header, instead of TCP), but this is not often required
except for extremely low-latency applications. Java uses the class DatagramSocket to
implement this functionality, although few developers should ever need to venture
this far down the network stack.
Finally, it's worth noting some changes that are currently in-flight in the addressing
schemes that are used across the Internet. The current version of IP that is in use is
Search WWH ::

Custom Search