Chapter 2. Sockets

In this chapter, we review Java’s socket classes. Sockets are an abstraction that allow two programs, usually on different machines, to communicate by sending data through streams. Strictly speaking, the socket classes (which are defined in the java.net package) are not part of RMI. However, RMI uses Java’s socket classes to handle communication between distinct processes. Thus, a basic knowledge of how sockets work is fundamental to understanding RMI. This chapter’s coverage, though far from complete, constitutes the core of what an RMI programmer needs to know.

Internet Definitions

The Internet is built out of computers that are connected by wires.[6] Each wire serves as a way to exchange information between the two computers it connects. Information is transferred in small, discrete chunks of data called datagrams.

Each datagram has a header and a data area. The header describes the datagram: where the datagram originated, what machines have handled the datagram, the type and length of the data being sent, and the intended destination of the the datagram. The data area consists of the actual information that is being sent. In almost all networking protocols, the data area is of limited size. For example, the Internet Protocol (frequently referred to as IP) restricts datagrams to 64 KB.

The Internet Protocol is also an example of what is frequently called a connectionless protocol—each datagram is sent independently, and there is no guarantee that any ...

Get Java RMI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.