Java Reference
In-Depth Information
distinguish fi rstly between a server and the machine upon which the server is running
(called the host machine), since I.T. workers often refer loosely to the host machine
as 'the server'. Though this common usage has no detrimental practical effects for
the majority of I.T. tasks, those I.T. personnel who are unaware of the distinction
and subsequently undertake network programming are likely to be caused a signifi -
cant amount of conceptual confusion until this distinction is made known to them.
A server, as the name implies, provides a service of some kind. This service is
provided for clients that connect to the server's host machine specifi cally for the
purpose of accessing the service. Thus, it is the clients that initiate a dialogue with
the server. (These clients, of course, are also programs and are not human clients!)
Common services provided by such servers include the 'serving up' of Web pages
(by Web servers) and the downloading of fi les from servers' host machines via the
File Transfer Protocol (FTP servers). For the former service, the corresponding
client programs would be Web browsers (such as Firefox, Chrome or Internet
Explorer). Though a client and its corresponding server will normally run on dif-
ferent machines in a real-world application, it is perfectly possible for such pro-
grams to run on the same machine. Indeed, it is often very convenient (as will be
seen in subsequent chapters) for server and client(s) to be run on the same machine,
since this provides a very convenient 'sandbox' within which such applications
may be tested before being released (or, more likely, before fi nal testing on sepa-
rate machines). This avoids the need for multiple machines and multiple testing
In some applications, such as messaging services, it is possible for programs on
users' machines to communicate directly with each other in what is called peer-to-
peer (or P2P ) mode. However, for many applications, this is either not possible or
prohibitively costly in terms of the number of simultaneous connections required.
For example, the World Wide Web simply does not allow clients to communicate
directly with each other. However, some applications use a server as an intermedi-
ary, in order to provide 'simulated'peer-to-peer facilities. Alternatively, both ends of
the dialogue may act as both client and server. Peer-to-peer systems are beyond the
intended scope of this text, though, and no further mention will be made of them.
Ports and Sockets
These entities lie at the heart of network communications. For anybody not already
familiar with the use of these terms in a network programming context, the two
words very probably conjure up images of hardware components. However,
although they are closely associated with the hardware communication links
between computers within a network, ports and sockets are not themselves hard-
ware elements, but abstract concepts that allow the programmer to make use of
those communication links.
A port is a logical connection to a computer (as opposed to a physical connec-
tion) and is identifi ed by a number in the range 1-65535. This number has no
Search WWH ::

Custom Search