Before data is sent across the Internet from one host to another using TCP/IP, it is split into packets of varying but finite size called datagrams. Datagrams range in size from a few dozen bytes to about 60,000 bytes. Anything larger than this, and often things smaller than this, needs to be split into smaller pieces before it can be transmitted. The advantage is that if one packet is lost, it can be retransmitted without requiring redelivery of all other packets. Furthermore if packets arrive out of order they can be reordered at the receiving end of the connection.

However this is all transparent to the Java programmer. The host's native networking software transparently handles the splitting of data into packets on the sending end of a connection, and the reassembly of packets on the receiving end. Instead, the Java programmer is presented witha higher level abstraction called a socket. The socket represents a reliable connection for the transmission of data between two hosts. It isolates you from the details of packet encodings, lost and retransmitted packets, and packets that arrive out of order.

There are four fundamental operations a socket performs. These are:

  1. Connect to a remote machine
  2. Send data
  3. Receive data
  4. Close the connection

A socket may not be connected to more than one host at a time.

Previous | Next | Top | Cafe au Lait

Copyright 1997, 2000 Elliotte Rusty Harold
Last Modified December 15, 2000