SlideShare a Scribd company logo
An Introduction to Network Programming with Java 1st
Edition Jan Graba download pdf
https://ebookfinal.com/download/an-introduction-to-network-programming-
with-java-1st-edition-jan-graba/
Visit ebookfinal.com today to download the complete set of
ebook or textbook!
Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Simply Java An Introduction to Java Programming
Programming Series 1st Edition James Levenick
https://ebookfinal.com/download/simply-java-an-introduction-to-java-
programming-programming-series-1st-edition-james-levenick/
Java An Introduction to Problem Solving and Programming
7th Edition Walter Savitch
https://ebookfinal.com/download/java-an-introduction-to-problem-
solving-and-programming-7th-edition-walter-savitch/
Introduction to Java Programming Comprehensive Version 6th
Edition Liang
https://ebookfinal.com/download/introduction-to-java-programming-
comprehensive-version-6th-edition-liang/
An introduction to programming with Mathematica 3rd
Edition Paul R. Wellin
https://ebookfinal.com/download/an-introduction-to-programming-with-
mathematica-3rd-edition-paul-r-wellin/
Wireless Java Programming with J2ME 1st Edition Yu Feng
https://ebookfinal.com/download/wireless-java-programming-
with-j2me-1st-edition-yu-feng/
Beginning Programming with Java For Dummies Third Edition
Barry Burd
https://ebookfinal.com/download/beginning-programming-with-java-for-
dummies-third-edition-barry-burd/
An Introduction to Stata Programming 2nd Edition
Christopher F. Baum
https://ebookfinal.com/download/an-introduction-to-stata-
programming-2nd-edition-christopher-f-baum/
Introduction to 3D game programming with DirectX 10 1st
Edition Frank D. Luna
https://ebookfinal.com/download/introduction-to-3d-game-programming-
with-directx-10-1st-edition-frank-d-luna/
Beginning Java 8 APIs Extensions and Libraries Swing
JavaFX JavaScript JDBC and Network Programming APIs 1st
Edition Kishori Sharan
https://ebookfinal.com/download/beginning-java-8-apis-extensions-and-
libraries-swing-javafx-javascript-jdbc-and-network-programming-
apis-1st-edition-kishori-sharan/
An Introduction to Network Programming with Java 1st Edition Jan Graba
An Introduction to Network Programming with Java 1st
Edition Jan Graba Digital Instant Download
Author(s): Jan Graba
ISBN(s): 9780321116147, 0321116143
Edition: 1
File Details: PDF, 2.62 MB
Year: 2007
Language: english
An Introduction to Network
Programming with Java
Jan Graba
An Introduction to Network
Programming with Java
Jan Graba, BA, PGCE, MSc
Faculty of ACES
Sheffield Hallam University
UK
British Library Cataloguing in Publication Data
A catalogue record for this book is available from the British Library
Library of Congress Control Number: 2006923894
ISBN-10: 1-84628-380-9
ISBN-13: 978-1-84628-380-2
Printed on acid-free paper
© Jan Graba 2007
New and revised edition of An Introduction to Network Programming with Java published by Addison
Wesley, 2003, ISBN 0321116143
Sun, Sun Microsystems, the Sun Logo, the Java programming language, J2SE 5.0, and JavaBeans are
trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.
Microsoft, Encarta, MSN, and Windows are either registered trademarks or trademarks of Microsoft
Corporation in the United States and/or other countries.
Apart from any fair dealing for the purposes of research or private study, or criticism or review, as
permitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced,
stored or transmitted, in any form or by any means, with the prior permission in writing of the publish-
ers, or in the case of reprographic reproduction in accordance with the terms of licences issued by the
Copyright Licensing Agency. Enquiries concerning reproduction outside those terms should be sent to
the publishers.
The use of registered names, trademarks, etc. in this publication does not imply, even in the absence of
a specific statement, that such names are exempt from the relevant laws and regulations and therefore
free for general use.
The publisher makes no representation, express or implied, with regard to the accuracy of the information
contained in this book and cannot accept any legal responsibility or liability for any errors or omissions
that may be made.
Whilst we have made considerable efforts to contact all holders of copyright material contained in this
book, we may have failed to locate some of them. Should holders wish to contact the Publisher, we will
be happy to come to some arrangement with them.
Printed in the United States of America (SB)
9 8 7 6 5 4 3 2 1
Springer Science+Business Media, LLC
springer.com
Preface
The market in general-purpose Java texts is an exceptionally well populated one, as
can be seen from just a cursory examination of the programming language section of
any major bookshop. Surprisingly, the market in Java network programming texts is
a much less exploited one, featuring very few texts. It is true that the better general-
purpose Java texts provide some guidance on aspects of network programming, but
this almost invariably takes the form of rather superficial coverage, often relegated to
the end of the particular text and offering little more than an outline of the relevant
concepts. Even those few texts that are devoted specifically to network programming
in Java (and one or two are very good indeed) are rather thick tomes that are
probably of greatest use as reference texts. The truth of this assertion appears to be
reinforced by the absence of practical exercises from such texts.
When I began work on the first edition of this work, my declared intention was to
write a more 'streamlined' work that could serve equally as the core text on an
undergraduate module and as the quick, clear, 'no-nonsense' guide required by a busy
IT professional. Numerous examples and associated screenshots were provided, with
the examples 'stripped down' to their bare essentials in order to avoid overwhelming
the reader with too much detail. There is, of course, a level of detail below which it
is impossible to go without omitting some of the essentials and this led to a few
examples running over multiple pages. However, a conscious effort was made to
keep this to a minimum and to provide adequate program comments where this did
occur.
It was gratifying to find that the first edition was well received, but the time has
now come to replace it with an updated version. The changes in this second edition
fall into three categories:
• language changes, largely reflecting the significant changes introduced
by J2SE 5.0 (but also including one or two changes brought in by earlier
versions of Java);
• the updating of support software, particularly that used for Web
applications;
• new material, some related to the changes introduced by J2SE 5.0
(otherwise known as Java 5) and some extending earlier coverage.
A summary of the major elements of these changes is given below.
Language Changes
These mostly affect the example programs and the model solutions provided on the
associated Web site. However, there are occasional, passing references to some of
these new features in the main body of the text where it is considered
appropriate. The main language changes introduced are listed below.
• Replacement of the BufferedReader+InputStreamReader combination with
the single Scanner class, with consequent erradication of the need to use the
vi An Introduction to Network Programming with Java
type 'wrapper' classes to convert String input into numeric values (a major
improvement on the traditional method for obtaining input).
• Associated with the above, replacement of the BufferedReader+FileReader
combination with Scanner+File and that of the PrintWriter+FileWriter
combination with PrintWriter+File for serial disc file I/O.
• Replacement of the cumbersome addWindowListener(new
WindowAdapter... method for closing down GUI applications with
setDefaultCloseOperation(EXIT_ON_CLOSE). (This had been available
since J2SE 1.3, but had deliberately not been included in the original text
due to the earlier method being the one still used by most people at that
time.)
• The formatting of numeric output (particularly decimal output) via method
printf.
• The inclusion of generics in the declaration of Vectors, with the associated
'auto-boxing' and 'auto-unboxing' of elements.
• Introduction of the 'enhanced for' loop where appropriate.
Updating of Support Software
• Replacement of the JSWDK Web server with Apache Tomcat.
• Replacement of the JavaBean Development Kit (BDK) with the Bean
Builder for the testing of JavaBeans.
• Removal of the section on the now defunct HTMLConverter utility and
updating of the example browsers to Internet Explorer 6 and Firefox 1.5.
New Material
• Coverage of non-blocking I/O (introduced in J2SE 1.4), but retaining
coverage of the more traditional blocking I/O.
• The use of JDBC with the DataSource interface (also introduced in J2SE
1.4), but maintaining coverage of the more traditional DriverManager class
approach. The associated examples are no longer confined to the use of MS
Access, but have been extended to include MySQL. The significant
advantages to large-scale, commercial databases of using DataSource in
preference to DriverManager are made clear to the reader.
• As part of good practice, the above DataSource technique makes use of a
DAO (Data Access Object) to encapsulate access to the database, so that
data manipulation code is separated from business logic.
On the CD-ROM accompanying this text may be found the executable file for
installing J2SE 5.0 onto MS Windows platforms (available via free download from
the Sun site, of course). In addition to this, the CD contains all example code and
several media files (the latter for use with material in the final two chapters). Model
solutions for end-of-chapter exercises are accessible by lecturers and other
authorised individuals from the companion Web site (accessible via
http://homepage.ntlworld.com/jan.graba/javanet.html). Finally, there is a document
entitled Java Environment Installation that provides downloading and installation
Preface vii
instructions for those additional software elements for which permission for
inclusion on the CD was not forthcoming. This document also contains installation
instructions (and downloading instructions, which shouldn't be required) for J2SE
5.0 itself.
I sincerely hope that your programming experiences while using this text give you
some of the sense of satisfaction that I have derived from writing it. Of course, along
with such satisfaction comes the occasional (?) infuriating sense of frustration when
things just won't work, but you wouldn't want things to be too easy ... would you??
:-)
Jan
22nd Feb 2006
Contents
Chapter 1 Basic Concepts, Protocols and Terminology ......................... 1
1.1 Clients, Servers and Peers ................................................................. 1
1.2 Ports and Sockets .............................................................................. 2
1.3 The Internet and IP Addresses .......................................................... 3
1.4 Internet Services, URLs and DNS .................................................... 4
1.5 TCP ................................................................................................... 5
1.6 UDP .................................................................................................. 7
Chapter 2 Starting Network Programming in Java ............................... 9
2.1 The InetAddress Class ...................................................................... 9
2.2 Using Sockets ................................................................................... 12
2.2.1 TCP Sockets ..... .................................................................... 12
2.2.2 Datagram (UDP) Sockets ....................................................... 18
2.3 Network Programming with GUIs ................................................... 28
2.4 Downloading Web Pages ................................................................. 37
Exercises ................................................................................................... 41
Chapter 3 Multithreading and Multiplexing .......................................... 51
3.1 Thread Basics ................................................................................... 51
3.2 Using Threads in Java ..................................................................... 52
3.2.1 Extending the Thread Class ................................................... 53
3.2.2 Explicitly Implementing the Runnable Interface ...................... 57
3.3 Multithreaded Servers ..................................................................... 60
3.4 Locks and Deadlock ........................................................................ 65
3.5 Synchronising Threads .................................................................... 67
3.6 Non-Blocking Servers ..................................................................... 74
3.6.1 Overview ................................................................................. 74
3.6.2 Implementation ......................................................................... 76
3.6.3 Further Details .......................................................................... 86
Exercises .................................................................................................. 88
Chapter 4 File Handling .......................................................................... 91
4.1 Serial Access Files .......................................................................... 91
4.2 File Methods ................................................................................... 97
4.3 Redirection .................................................................................... 99
4.4 Command Line Parameters ............................................................ 101
4.5 Random Access Files ..................................................................... 102
4.6 Serialisation .................................................................................... 109
4.7 File I/O with GUIs ......................................................................... 113
4.8 Vectors ........................................................................................... 120
4.9 Vectors and Serialisation ............................................................... 123
Contents ix
Exercises ................................................................................................. 132
Chapter 5 Remote Method Invocation (RMI) ...................................... 136
5.1 The Basic RMI Process .................................................................. 136
5.2 Implementation Details .................................................................. 137
5.3 Compilation and Execution ............................................................ 141
5.4 Using RMI Meaningfully ............................................................... 143
5.5 RMI Security .................................................................................. 153
Exercises ................................................................................................. 156
Chapter 6 CORBA ................................................................................... 158
6.1 Background and Basics ................................................................... 158
6.2 The Structure of a Java IDL Specification ...................................... 159
6.3 The Java IDL Process ...................................................................... 163
6.4 Using Factory Objects ..................................................................... 173
6.5 Object Persistence ........................................................................... 184
6.6 RMI-IIOP ........................................................................................ 184
Exercises .................................................................................................. 186
Chapter 7 Java Database Connectivity (JDBC) ................................... 188
7.1 The Vendor Variation Problem ....................................................... 188
7.2 SQL and Versions of JDBC ............................................................ 189
7.3 Creating an ODBC Data Source ..................................................... 190
7.4 Simple Database Access .................................................................. 191
7.5 Modifying the Database Contents ................................................... 199
7.6 Transactions .................................................................................... 203
7.7 Meta Data ........................................................................................ 204
7.8 Using a GUI to Access a Database ................................................. 207
7.9 Scrollable ResultSets in JDBC 2.0 .................................................. 210
7.10 Modifying Databases via Java Methods ......................................... 215
7.11 Using the DataSource Interface ...................................................... 220
7.11.1 Overview and Support Software ............................................ 220
7.11.2 Defining a JNDI Resource Reference ....................................... 222
7.11.3 Mapping the Resource Reference onto a Real Resource ........... 223
7.11.4 Obtaining the Data Source Connection ..................................... 225
7.11.5 Data Access Objects .................................................................. 226
Exercises .................................................................................................. 232
Chapter 8 Servlets .................................................................................... 234
8.1 Servlet Basics .................................................................................... 234
8.2 Setting up the Servlet API ............................................................... 235
8.3 Creating a Web Application ............................................................ 237
8.4 The Servlet URL and the Invoking Web Page ................................ 239
8.5 Servlet Structure ............................................................................... 240
8.6 Testing a Servlet .............................................................................. 242
8.7 Passing Data .................................................................................... 242
x An Introduction to Network Programming with Java
8.8 Sessions ........................................................................................... 249
8.9 Cookies ............................................................................................ 260
8.10 Accessing a Database Via a Servlet ................................................ 268
Exercises .................................................................................................. 275
Chapter 9 JavaServer Pages (JSPs) ........................................................ 278
9.1 The Rationale behind JSPs ............................................................... 278
9.2 Compilation and Execution ............................................................. 279
9.3 JSP Tags .......................................................................................... 280
9.4 Implicit JSP Objects ........................................................................ 283
9.5 Collaborating with Servlets ............................................................. 285
9.6 JSPs in Action ................................................................................. 285
9.7 Error Pages ...................................................................................... 291
9.8 Using JSPs to Access Remote Databases ....................................... 294
Exercises .................................................................................................. 295
Chapter 10 JavaBeans ................................................................................ 297
10.1 Introduction to the Bean Builder .................................................... 298
10.2 Creating a JavaBean ....................................................................... 301
10.3 Exposing a Bean's Properties ......................................................... 307
10.4 Making Beans Respond to Events ................................................. 311
10.5 Using JavaBeans within an Application ........................................ 315
10.6 Bound Properties ........................................................................... 317
10.7 Using JavaBeans in JSPs ............................................................... 324
10.7.1 The Basic Procedure ........................................................ 324
10.7.2 Calling a Bean's Methods Directly .................................. 326
10.7.3 Using HTML Tags to Manipulate a Bean's Properties .... 330
Exercises .................................................................................................. 342
Chapter 11 Introduction to Enterprise JavaBeans ................................. 345
11.1 Categories of EJB ........................................................................... 345
11.2 Basic Structure of an EJB ............................................................... 346
11.3 Packaging and Deployment ............................................................ 349
11.4 Client Programs .............................................................................. 351
11.5 Entity EJBs ..................................................................................... 353
Chapter 12 Multimedia ............................................................................. 359
12.1 Transferring and Displaying Images Easily ................................... 360
12.2 Transferring Media Files ................................................................ 365
12.3 Playing Sound Files ....................................................................... 370
12.4 The Java Media Framework ........................................................... 372
Exercises ................................................................................................. 379
Chapter 13 Applets ................................................................................... 380
13.1 Applets and JApplets ...................................................................... 380
Contents xi
13.2 Applet Basics and the Development Process ................................. 381
13.3 The Internal Operation of Applets .................................................. 385
13.4 Using Images in Applets ................................................................ 392
13.4.1 Using Class Image ........................................................... 392
13.4.2 Using Class ImageIcon .................................................... 397
13.5 Scaling Images ................................................................................ 400
13.6 Using Sound in Applets .................................................................. 401
Exercises .................................................................................................. 405
Appendix A Structured Query Language (SQL) ............................. 406
Appendix B Deployment Descriptors for EJBs ................................ 411
Appendix C Further Reading ............................................................. 414
Index ............................................................................................................. 417
1 Basic Concepts, Protocols and Terminology
Learning Objectives
After reading this chapter, you should:
• have a high level appreciation of the basic means by which
messages are sent and received on modern networks;
• be familiar with the most important protocols used on networks;
• understand the addressing mechanism used on the Internet;
• understand the basic principles of client/server programming.
The fundamental purpose of this opening chapter is to introduce the underpinning
network principles and associated terminology with which the reader will need to be
familiar in order to make sense of the later chapters of this book. The material
covered here is entirely generic (as far as any programming language is concerned)
and it is not until the next chapter that we shall begin to consider how Java may be
used in network programming. If the meaning of any term covered here is not clear
when that term is later encountered in context, the reader should refer back to this
chapter to refresh his/her memory.
It would be very easy to make this chapter considerably larger than it currently is,
simply by including a great deal of dry, technical material that would be unlikely to
be of any practical use to the intended readers of this book. However, this chapter is
intentionally brief, the author having avoided the inclusion of material that is not of
relevance to the use of Java for network programming. The reader who already has a
sound grasp of network concepts may safely skip this chapter entirely.
1.1 Clients, Servers and Peers
The most common categories of network software nowadays are clients and servers.
These two categories have a symbiotic relationship and the term client/server
programming has become very widely used in recent years. It is important to
distinguish firstly 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 significant 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 specifically 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
2 An Introduction to Network Programming with Java
(by Web servers) and the downloading of files 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 Netscape Communicator or
Microsoft Explorer). Though a client and its corresponding server will normally run
on different machines in a real-world application, it is perfectly possible for such
programs 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 final testing on separate
machines). This avoids the need for multiple machines and multiple testing
personnel.
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
intermediary, 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.
1.2 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 hardware
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 connection)
and is identified by a number in the range 1-65535. This number has no
correspondence with the number of physical connections to the computer, of which
there may be only one (even though the number of ports used on that machine may
be much greater than this). Ports are implemented upon all computers attached to a
network, but it is only those machines that have server programs running on them
for which the network programmer will refer explicitly to port numbers. Each port
may be dedicated to a particular server/service (though the number of available ports
will normally greatly exceed the number that is actually used). Port numbers in the
range 1-1023 are normally set aside for the use of specified standard services, often
referred to as 'well-known' services. For example, port 80 is normally used by Web
servers. Some of the more common well-known services are listed in Section 1.4.
Application programs wishing to use ports for non-standard services should avoid
using port numbers 1-1023. (A range of 1024-65535 should be more than enough for
even the most prolific of network programmers!)
Basic Concepts, Protocols and Terminology 3
For each port supplying a service, there is a server program waiting for any
requests. All such programs run together in parallel on the host machine. When a
client attempts to make connection with a particular server program, it supplies the
port number of the associated service. The host machine examines the port number
and passes the client’s transmission to the appropriate server program for
processing.
In most applications, of course, there are likely to be multiple clients wanting the
same service at the same time. A common example of this requirement is that of
multiple browsers (quite possibly thousands of them) wanting Web pages from the
same server. The server, of course, needs some way of distinguishing between
clients and keeping their dialogues separate from each other. This is achieved via the
use of sockets. As stated earlier, a socket is an abstract concept and not an element
of computer hardware. It is used to indicate one of the two end-points of a
communication link between two processes. When a client wishes to make
connection to a server, it will create a socket at its end of the communication link.
Upon receiving the client's initial request (on a particular port number), the server
will create a new socket at its end that will be dedicated to communication with that
particular client. Just as one hardware link to a server may be associated with many
ports, so too may one port be associated with many sockets. More will be said about
sockets in Chapter 2.
1.3 The Internet and IP Addresses
An internet (lower-case 'i') is a collection of computer networks that allows any
computer on any of the associated networks to communicate with any other
computer located on any of the other associated networks (or on the same network,
of course). The protocol used for such communication is called the Internet Protocol
(IP). The Internet (upper-case 'I') is the world's largest IP-based network. Each
computer on the Internet has a unique IP address, the current version of which is
IPv4 (Internet Protocol version 4). This represents machine addresses in what is
called quad notation. This is made up of four eight-bit numbers (i.e., numbers in
the decimal range 0-255), separated by dots. For example, 131.122.3.219 would be
one such address. Due to a growing shortage of IPv4 addresses, IPv4 is due to be
replaced with IPv6, the draft standard for which was published on the 10th of
August, 1998. IPv6 uses 128-bit addresses, which provide massively more
addresses. Many common Internet applications already work with IPv6 and it is
expected that IPv6 will gradually replace IPv4, with the two coexisting for a number
of years during a transition period.
Recent years have witnessed an explosion in the growth and use of the Internet. As
a result, there has arisen a need for a programming language with features designed
specifically for network programming. Java provides these features and does so in a
platform-independent manner, which is vital for a heterogeneous network such as
the Internet. Java is sometimes referred to as 'the language of the Internet' and it is
the use of Java in this context that has had a major influence on the popularisation of
the language. For many programmers, the need to program for the Internet is one of
the main reasons, if not the reason, for learning to program in Java.
4 An Introduction to Network Programming with Java
1.4 Internet Services, URLs and DNS
Whatever the service provided by a server, there must be some established protocol
governing the communication that takes place between server and client. Each end
of the dialogue must know what may/must be sent to the other, the format in which
it should be sent, the sequence in which it must be sent (if sequence matters) and, for
'open-ended' dialogues, how the dialogue is to be terminated. For the standard
services, such protocols are made available in public documents, usually by either
the Internet Engineering Task Force (IETF) or the World Wide Web Consortium
(W3C). Some of the more common services and their associated ports are shown in
Figure 1.1. For a more esoteric or 'bespoke' service, the application writer must
establish a protocol and convey it to the intended users of that service.
Protocol
name
Port
number
Nature of service
Echo 7 The server simply echoes the data
sent to it. This is useful for testing
purposes.
Daytime 13 Provides the ASCII representation of
the current date and time on the
server.
FTP-data 20 Transferring files. (FTP uses two
ports.)
FTP 21 Sending FTP commands like PUT
and GET.
Telnet 23 Remote login and command line
interaction.
SMTP 25 E-mail. (Simple Mail Transfer
Protocol.)
HTTP 80 HyperText Transfer Protocol
(the World Wide Web protocol).
NNTP 119 Usenet. (Network News
Transfer Protocol.)
Table 1.1 Some well-known network services.
A URL (Uniform Resource Locator) is a unique identifier for any resource
located on the Internet. It has the following structure (in which BNF notation is
used):
<protocol>://<hostname>[:<port>][/<pathname>][/<filename>[#<section>]]
For example:
http://java.sun.com/j2se/1.5.0/download.jsp
Basic Concepts, Protocols and Terminology 5
For a well-known protocol, the port number may be omitted and the default port
number will be assumed. Thus, since the example above specifies the HTTP
protocol (the protocol of the Web) and does not specify on which port of the host
machine the service is available, it will be assumed that the service is running on
port 80 (the default port for Web servers). If the file name is omitted, then the server
sends a default file from the directory specified in the path name. (This default file
will commonly be called index.html or default.html.) The 'section' part of the URL
(not often specified) indicates a named 'anchor' in an HTML document. For
example, the HTML anchor in the tag
<A NAME="thisPlace"></A>
would be referred to as thisPlace by the section component of the URL.
Since human beings are generally much better at remembering meaningful strings
of characters than they are at remembering long strings of numbers, the Domain
Name System was developed. A domain name, also known as a host name, is the
user-friendly equivalent of an IP address. In the previous example of a URL, the
domain name was java.sun.com. The individual parts of a domain name don't
correspond to the individual parts of an IP address. In fact, domain names don't
always have four parts (as IPv4 addresses must have).
Normally, human beings will use domain names in preference to IP addresses, but
they can just as well use the corresponding IP addresses (if they know what they
are!). The Domain Name System provides a mapping between IP addresses and
domain names and is held in a distributed database. The IP address system and the
DNS are governed by ICANN (the Internet Corporation for Assigned Names and
Numbers), which is a non-profitmaking organisation. When a URL is submitted to a
browser, the DNS automatically converts the domain name part into its numeric IP
equivalent.
1.5 TCP
In common with all modern computer networks, the Internet is a packet-switched
network, which means that messages between computers on the Internet are broken
up into blocks of information called packets, with each packet being handled
separately and possibly travelling by a completely different route from that of other
such packets from the same message. IP is concerned with the routing of these
packets through an internet. Introduced by the American military during the Cold
War, it was designed from the outset to be robust. In the event of a military strike
against one of the network routers, the rest of the network had to continue to
function as normal, with messages that would have gone through the damaged router
being re-routed. IP is responsible for this re-routing. It attaches the IP address of the
intended recipient to each packet and then tries to determine the most efficient route
available to get to the ultimate destination (taking damaged routers into account).
However, since packets could still arrive out of sequence, be corrupted or even
not arrive at all (without indication to either sender or intended recipient that
6 An Introduction to Network Programming with Java
anything had gone wrong), it was decided to place another protocol layer on top of
IP. This further layer was provided by TCP (Transmission Control Protocol), which
allowed each end of a connection to acknowledge receipt of IP packets and/or
request retransmission of lost or corrupted packets. In addition, TCP allows the
packets to be rearranged into their correct sequence at the receiving end. IP and TCP
are the two commonest protocols used on the Internet and are almost invariably
coupled together as TCP/IP. TCP is the higher level protocol that uses the lower
level IP.
For Internet applications, a four-layer model is often used, which is represented
diagrammatically in Figure 1.1 below. The transport layer will often comprise the
TCP protocol, but may be UDP (described in the next section), while the internet
layer will always be IP. Each layer of the model represents a different level of
abstraction, with higher levels representing higher abstraction. Thus, although
applications may appear to be communicating directly with each other, they are
actually communicating directly only with their transport layers. The transport and
internet layers, in their turn, communicate directly only with the layers immediately
above and below them, while the host-to-network layer communicates directly only
with the IP layer at each end of the connection. When a message is sent by the
application layer at one end of the connection, it passes through each of the lower
layers. As it does so, each layer adds further protocol data specific to the particular
protocol at that level. For the TCP layer, this process involves breaking up the data
packets into TCP segments and adding sequence numbers and checksums; for the IP
layer, it involves placing the TCP segments into IP packets called datagrams and
adding the routing details. The host-to-network layer then converts the digital data
into an analogue form suitable for transmission over the carrier wire, sends the data
and converts it back into digital form at the receiving end.
Figure 1.1 The 4-Layer Network Model
At the receiving end, the message travels up through the layers until it reaches the
receiving application layer. As it does so, each layer converts the message into a
form suitable for receipt by the next layer (effectively reversing the corresponding
process carried out at the sending end) and carries out checks appropriate to its own
Application Layer
Internet Layer (IP)
Internet Layer (IP)
Application Layer
Transport Layer (E.g., TCP)
Transport Layer (E.g., TCP)
path
Logical
Host-to-network layer
Basic Concepts, Protocols and Terminology 7
protocol. If recalculation of checksums reveals that some of the data has been
corrupted or checking of sequence numbers shows that some data has not been
received, then the transport layer requests re-transmission of the corrupt/missing
data. Otherwise, the transport layer acknowledges receipt of the packets. All of this
is completely transparent to the application layer. Once all the data has been
received, converted and correctly sequenced, it is presented to the recipient
application layer as though that layer had been in direct communication with the
sending application layer. The latter may then send a response in exactly the same
manner (and so on). In fact, since TCP provides full duplex transmission, the two
ends of the connection may be sending data simultaneously.
The above description has deliberately hidden many of the low-level details of
implementation, particularly the tasks carried out by the host-to-network layer. In
addition, of course, the initial transmission may have passed through several routers
and their associated layers before arriving at its ultimate destination. However, this
high-level view covers the basic stages that are involved and is quite sufficient for
our purposes.
Another network model that is often referred to is the seven-layer Open Systems
Interconnection (OSI) model. However, this model is an unnecessarily complex one
for our purposes and is better suited to non-TCP/IP networks anyway.
1.6 UDP
Most Internet applications use TCP as their transport mechanism. Unfortunately, the
checks built into TCP to make it such a robust protocol do not come without a cost.
The overhead of providing facilities such as confirmation of receipt and re-
transmission of lost or corrupted packets means that TCP is a relatively slow
transport mechanism. For many applications (e.g., file transfer), this does not really
matter greatly. For these applications, it is much more important that the data arrives
intact and in the correct sequence, both of which are guaranteed by TCP. For some
applications, however, these factors are not the most important criteria and the
relatively slow throughput speed provided by TCP is simply not feasible. Such
applications include the playing of audio and video while the associated files are
being downloaded, via what is called streaming. One of the most popular streaming
technologies is called RealAudio. RealAudio does not use TCP, because of its large
overhead. This and other such applications use User Datagram Protocol (UDP).
UDP is an unreliable protocol, since:
• it doesn't guarantee that each packet will arrive;
• it doesn't guarantee that packets will be in the right order.
UDP doesn't re-send a packet if it is missing or there is some other error, and it
doesn't assemble packets into the correct order. However, it is significantly faster
than TCP. For applications such as the streaming of audio or video, losing a few bits
of data is much better than waiting for re-transmission of the missing data. The
major objective in these two applications is to keep playing the sound/video without
8 An Introduction to Network Programming with Java
interruption. In addition, it is possible to build error-checking code into the UDP
data streams to compensate for the missing data.
2 Starting Network Programming in Java
Learning Objectives
After reading this chapter, you should :
• know how to determine the host machine's IP address via a Java
program;
• know how to use TCP sockets in both client programs and server
programs;
• know how to use UDP sockets in both client programs and server
programs;
• appreciate the convenience of Java's stream classes and the
consistency of the interface afforded by them;
• appreciate the ease with which GUIs can be added to network
programs;
• know how to check whether ports on a specified machine are
running services;
• know how to use Java to render Web pages.
Having covered fundamental network protocols and techniques in a generic fashion
in Chapter 1, it is now time to consider how those protocols may be used and the
techniques implemented in Java. Core package java.net contains a number of very
useful classes that allow programmers to carry out network programming very
easily. Package javax.net, introduced in J2SE 1.4, contains factory classes for
creating sockets in an implementation-independent fashion. Using classes from
these packages (primarily from the former), the network programmer can
communicate with any server on the Internet or implement his/her own Internet
server.
2.1 The InetAddress Class
One of the classes within package java.net is called InetAddress, which handles
Internet addresses both as host names and as IP addresses. Static method getByName
of this class uses DNS (Domain Name System) to return the Internet address of a
specified host name as an InetAddress object. In order to display the IP address from
this object, we can simply use method println (which will cause the object's
toString method to be executed). Since method getByName throws the checked
exception UnknownHostException if the host name is not recognised, we must
either throw this exception or (preferably) handle it with a catch clause. The
following example illustrates this.
10 An Introduction to Network Programming with Java
Example
import java.net.*;
import java.util.*;
public class IPFinder
{
public static void main(String[] args)
{
String host;
Scanner input = new Scanner(System.in);
System.out.print("nnEnter host name: ");
host = input.next();
try
{
InetAddress address =
InetAddress.getByName(host);
System.out.println("IP address: "
+ address.toString());
}
catch (UnknownHostException uhEx)
{
System.out.println("Could not find " + host);
}
}
}
The output from a test run of this program is shown in Figure 2.1.
Figure 2.1 Using method getByName to retrieve IP address of a specified host.
Random documents with unrelated
content Scribd suggests to you:
Mr. A. M. Watkin became locomotive superintendent of the South
Eastern Railway in 1876, and he introduced a very pretty design of
express passenger engines. Twenty engines of the type were
constructed: Nos. 259 to 268 by Sharp, Stewart, and Co., and Nos.
269 to 278 by the Avonside Engine Company. Inside frames were
provided; the leading wheels were 4ft. and the four-coupled wheels
6ft. 6in. diameter. The cylinders were 17in. diameter and 24in.
stroke. The weight in working order was 34½ tons; the total heating
surface, 1,103½ sq. ft. The splashers to the coupled wheels were of
open-work design. The chimney was of the rimless South Eastern
pattern; a dome was provided on the centre of the boiler barrel, and
a duplex safety valve on the fire-box top. A cab very much
resembling the standard London and North Western Railway pattern
was fitted to the engines.
Several of these engines, as rebuilt by Mr. Stirling, remain in work
at the present time; they are principally employed on the Mid-Kent
services.
In 1874 Mr. Stroudley, the then locomotive superintendent of the
London, Brighton and South Coast Railway, built the “Grosvenor”
with 6ft. 9in. single driving wheels, inside cylinders 17in. by 24in.,
and a total heating surface of 1,132 sq. ft. The “Stroudley” speed
indicator was fitted to this engine. On August 13th, 1876, the
“Grosvenor” conveyed a train from Victoria to Portsmouth (87 miles)
without a stop. This was the first occasion on which such a trip had
been performed; the time taken was 110 minutes.
No other engine exactly similar to the “Grosvenor” was
constructed; but in 1877 the “Abergavenny”—with 6ft. 6in. single
drivers and cylinders 16in. by 22in.—was built, and in 1880 the first
of the “G” class of singles was turned out at the Brighton Works.
These also have single driving wheels 6ft. 6in. in diameter, but the
cylinders are 17in. diameter, the stroke being 24in. The weight on
the driving wheel is 13 tons.
An interesting era in the evolution of the steam locomotive is at
this point arrived at—viz., the first really practical trial of compound
engines, or the use of steam twice over for the purpose of propelling
a locomotive.
To Mr. Webb, the chief mechanical engineer of the London and
North Western Railway, is due the honour of introducing the
compound system on an extended scale in railway practice.
Although 21 years have now passed since the premier attempt of
giving the system a fair trial on an English railway was made, it does
not seem to have gained much favour with English locomotive
engineers. Indeed, at the present time, excepting a few minor trials
elsewhere, the London and North Western Railway is the only
company that constructs and uses compound locomotives.
Mr. Webb employs the three-cylinder type of engine, which is an
adaptation of the system introduced by M. Mallet on the Bayonne
and Biarritz Railway. Three engines were built from Mr. Mallet’s
design by Schneider and Co., Creusot, and were brought into use in
July, 1876. In these locomotives Mallet employed two outside
cylinders, one being 15¾in. and the other 9½in. diameter.
Mr. Webb uses three cylinders: an inside cylinder for the l.p.
steam and two outside cylinders for the high-pressure steam. But at
first one of Trevithick’s old “single” engines was fitted up on Mallet’s
two-cylinder plan. This was in 1878. The engine worked successfully
for five years on the Ashley and Nuneaton branch of the London and
North Western Railway, and thereupon Mr. Webb decided to
construct compound engines on his three-cylinder system.
The first of such engines was the “Experiment.” Her outside h.p.
cylinders were 11½in. diameter, the inside l.p. being 26in. diameter.
Joy’s celebrated valve gear was employed to regulate the admission
of steam to the cylinders.
“Webb” compounds have two pairs of driving wheels, but these
are uncoupled, so that practically the engines are “singles.” Whether
the four driving wheels work well together, or whether, on the other
hand, there exists a considerable amount of either slip or skidding is
another matter. The trailing pair of wheels is driven from the h.p.
cylinders, and the middle pair from the inside or l.p. cylinder.
Mr. Bowen-Cooke, an authority on London and North Western
Railway locomotive practice, sums up the advantages of the “Webb”
compound system under the five following heads:—
1. Greater power.
2. Economy in the consumption of fuel.
3. The whole of the available power of the steam used.
4. A more even distribution of the strains upon the working parts,
and larger bearing surfaces for the axles.
5. The same freedom of running as with a single engine, with the
same adhesion to the rails as a coupled engine.
The 6ft. wheel type of London and North Western Railway
compound was introduced in 1884. The outside cylinders are 14in.
and the inside 30in. diameter, stroke 24in. Joy’s gear is used for all
the valves; the valves to the outside cylinders are below, and the
valve of the l.p. cylinder is above the cylinder. The boiler steam-
pressure is 175lb. per square in., but it is reduced to 80lb. when
entering the low-pressure cylinder. The weight of the engine in
working order is 42 tons 10 cwt. Heating surface: Tubes, 1,242 sq.
ft.; fire-box, 159.1 sq. ft.; total, 1,401.5 sq. ft. Grate area, 20.5 sq. ft.
Fig. 95.—“TEUTONIC,” A L. & N.W.R. “COMPOUND”
LOCOMOTIVE ON WEBB’S SYSTEM
An engine built to this design—the “Marchioness of Stafford”—
was exhibited at the London Inventions Exhibition of 1885, and
gained the gold medal.
In 1890 the first of the “Teutonic” (Fig. 95) class of 7ft. 1in.
compounds was constructed at Crewe Works. The leading wheels of
this type are 4ft. 1½in. diameter. Total weight in working order, 45
tons 10 cwt. In these engines Mr. Webb’s loose eccentric motion is
used for the low-pressure inside cylinder, but Joy’s gear is retained
for the h.p. outside cylinders.
Fig. 96.—“QUEEN EMPRESS,” ONE OF WEBB’S
COMPOUND LOCOMOTIVES, L. & N.W.R.
Another type of compound is the “Greater Britain.” During 1897
the “Greater Britain” and other engines of the class were coloured
red, white, and blue, and employed to haul the Royal train when
travelling over the London and North Western Railway system. They
were then nicknamed the “Diamond Jubilees.”
The special feature of this class is the length of the boiler, which
is divided into two portions by means of a central combustion
chamber. The heating surface is: fire-box, 120.6 sq. ft.; combustion
chamber, 39.1 sq. ft.; front set of tubes, 875 sq. ft.; back set of tubes,
506.2 sq. ft. total, 1540.9 sq. ft. The two pairs of driving wheels are
located in front of the fire-box, and in addition there are a pair of
leading and a pair of trailing wheels.
An engine of this class—the “Queen Empress” (Fig. 96)—was
exhibited at the World’s Fair held at Chicago in 1893. Her leading
dimensions are: Two high-pressure cylinders, 15in. diameter by 24in.
stroke; one low-pressure cylinder, 30in. diameter by 24in. stroke;
wheels—driving, 7ft. 1in. diameter (four in number); leading, 4ft.
1½in. diameter; trailing, 4ft. 1½in. diameter. Weight on each pair of
driving wheels, 16 tons. Total weight of engine in working order, 52
tons 15 cwt. Total wheel base, 23ft. 8in. Centre to centre of driving
wheels, 8ft. 3in.
The most recent type of compound goods locomotives
constructed by Mr. Webb has eight-coupled wheels, three pairs of
which are located under the fire-box, the trailing pair being close to
the back of the fire-box. The outside cylinders are below the top of
the frame-plate, and incline towards the rear. This type of engine
was designed by Mr. F. W. Webb, chief mechanical engineer of the
London and North Western Railway, principally for working the heavy
mineral traffic over that Company’s South Wales district, the first
engine being built in 1893. The wheels (all coupled) are 4ft. 5½in. in
diameter, with tyres 3in. thick. The distance between the centres of
each pair is 5ft. 9in., the total wheel base being 17ft. 3in. All the
cylinders drive on to one axle—the second from the front of the
engine; the two high-pressure cylinders are connected to crank pins
in the wheels set at right angles to each other, the low-pressure
cylinder being connected to a centre crank-pin set at an angle of 135
degrees with the high-pressure cranks; the high-pressure cylinders
are 15in. diameter by 24in. stroke, and the low-pressure cylinders
are 30in. diameter by 24in. stroke. All the cylinders are bolted
together and in line, the low-pressure being placed immediately
under the smoke-box, and the high-pressure cylinders on each side
outside the frames, the steam chests being within the frames.
The engine weighs, in working order, 53 tons 18 cwt.
The empty weights are as follows:—
Tons. Cwts.
Leading wheels 12 10
Driving wheels 14 8
Intermediate wheels 12 14
Trailing wheels 9 15
Total (Empty) 47 47
The latest type of a passenger compound locomotive built by Mr
Webb is the 7ft. four-wheels-coupled engine “Black Prince” (Fig. 97),
which was built at the Crewe Works in July, 1897.
The engine has two high-pressure and two low-pressure
cylinders, all being in line, and driving on to one axle, the high and
low pressure cranks being directly opposite each other.
One of the features of this engine is the method adapted for
working the valves, two sets of gear only being used for working the
four valves.
Joy’s valve motion is used for the low-pressure valves, the valve
spindles being prolonged through the front of the steam chest, and
on the end of the spindle a cross-head is fixed which engages with a
lever of the first order, carried on a pivot firmly secured to the engine
frame. The other end of this lever engages with a cross-head fixed
on the end of the high pressure valve spindle, and by this means the
requisite motion is given to the high pressure valve.
The leading end of the engine is carried on a double radial truck,
the centre of which is fitted with Mr. Webb’s radial axle-box and
central controlling spring. This arrangement permits of 1in. side play,
and gives greater freedom to the truck when passing round curves
than is possible in the ordinary type of bogie with a rigid centre-pin.
One important object aimed at in the construction of this engine
has been to get all the bearing surfaces throughout as large as
possible. Each of the four journals in the radial truck is 6¼in.
diameter and 1Oin. long. The driving axle, in addition to the two
ordinary bearings, which are each 7½in. diameter and 9in. long, has
a central bearing between the two cranks, 7in. diameter and 5½in.
long. In the trailing axle the journals are 7½in. diameter, by 13½in.
long.
This engine made its first trip on August 2nd, 1897, and since
then has been principally engaged in working the “up” dining saloon
express, which leaves Crewe at 5.20 p.m., running through to
Willesden without a stop—a distance of 152½ miles—and returning
the same night with the Scotch sleeping saloon express, which
leaves Euston at 11.50 p.m., running through to Crewe without a
stop, 158 miles.
Fig. 97.—“BLACK PRINCE,” L. & N.W.R., A 4-
COUPLED 4-CYLINDER, COMPOUND
ENGINE, WITH DOUBLE RADIAL TRACK
The total distance run by this engine up to June 30th, 1898, was
52,034 miles.
The high-pressure cylinders are 15in. diameter by 24in. stroke,
and the low-pressure cylinders are 20½in. diameter by 24in. stroke.
The heating surface is: Tubes, 1,241.3 sq. ft.; fire-box, 159.1 sq.
ft.; total 1,409.1 sq. ft. Grate area, 20.5 sq. ft.
A concise survey of other compound locomotives will be of
interest at this juncture.
Mr. Wordsell, the then locomotive superintendent of the Great
Eastern Railway, in 1882 built a compound engine, with two inside
cylinders, the h.p. 18in. and the l.p. 26in. diameter; the stroke was
24in.; steam pressure, 160lb. per sq. in. The coupled wheels were
7ft. diameter. The engine was fitted with a leading bogie, the wheels
of which were 3ft. 1in. diameter; with her tender she weighed 77 tons
in working order; her number was 230. A similar engine, No. 702,
with Joy’s valve gear, was built in 1885.
Mr. Wordsell also built a two-cylinder, six-coupled goods engine
for the Great Eastern Railway, on the compound principle. This was
fitted with the ordinary link motion.
Mr. Wordsell, upon his appointment as locomotive superintendent
of the North Eastern Railway, introduced compound engines on that
line. These were provided with two cylinders, both inside, with the
valves on top.
The h.p. cylinder is 18in. and the l.p. 26in. in diameter, the stroke
being 24in. Mr. Worthington thus describes the North Eastern
Railway standard compound goods engine:—“In outside appearance
this engine is neat, simple, and substantial. It weighs 40 tons 7 cwt.,
and has six coupled 5ft. 1¼in. in diameter.
“The cylinders are placed, as in the passenger compound
engines, beneath the slide-valves and inside the frames.
“The chief features of this goods engine to be observed are the
starting and intercepting valves, which enable the engine-driver to
start the engine by admitting sufficient high-pressure steam to the
large cylinder without interfering with the small cylinder, in case the
latter is not in a position to start the train alone.
“The two valves are operated by steam controlled by one handle.
If the engine does not start when the regulator is opened, which will
occur when the high-pressure valve covers both steam ports, the
driver pulls the additional small handle, which closes the passage
from the receiver to the low-pressure cylinder, and also admits a
small amount of steam to the low-pressure steam chest, so that the
two cylinders together develop additional starting power.
“After one or two strokes of the engine the exhaust steam from
the high-pressure cylinder automatically forces the two valves back
to their normal position, and the engine proceeds working
compound.”
The North Eastern Railway has other compound engines
constructed on the Wordsell and Van Borries system, a 6ft. 8¼in.
four-coupled, with a leading bogie of locomotive, being turned out in
1886. Engines of this type have a heating surface of 1,323.3 sq. ft., a
grate area of 17.33 sq. ft., and a working pressure of 175lb. per sq.
in.
Another North Eastern Railway type of compound has 7ft. 6in.
single driving wheels and a leading bogie. The h.p. cylinder is 20in.,
and the l.p. 26in. diameter, compared with 18in. and 26in. in the four-
coupled class, the stroke being the same in each design—viz., 24in.
The first of the 7ft. 6in. compound class of locomotives was
constructed at the Gateshead Works in 1890. The engines of this
design appear capable of doing very heavy work with a low coal
consumption, the average being 28lb. per mile, which, considering
the heavy traffic and speed maintained, is low, being, in fact, 2lb. per
mile below that of any other class of engine engaged on the same
traffic.
With a train of 18 coaches, weighing 310 tons (including 87 tons,
the weight of the engine and tender), a speed of 86 miles an hour
was attained on a level portion of the road, the horse-power
indicated being 1,068. These engines have a commodious cab, and
the tenders carrying 3,900 gallons of water, thus making it possible
for the run of 125 miles, from Newcastle to Edinburgh, to be
performed without a stop. There is also a class of six-coupled tank
engines, with a trailing radial axle. The stroke is 24in., and the
diameter of cylinders h.p. 18in., and l.p. 26in. Compound engines
have also been tried on the Glasgow and South Western Railway
and on the London and South Western Railway.
The advantages of express locomotives being fitted with leading
bogies were speedily recognised by most of the locomotive
superintendents. Mr. S. W. Johnson, the Midland chief, introduced a
design of such engines in 1876. The steam pressure of the early
engines of this class was 140lb., but in later years this was increased
to 160lb., whilst in the recent engines the pressure is still further
augmented.
The same progress is to be noticed in the diameter of the
cylinders of the Midland engines, the diameter having increased from
17½in. in 1876 to 19½in. at the present time. The size of the coupled
wheels has also increased from 6ft. 6in. to 7ft. 9in. The length of
stroke has been the same in all engines of this design—viz., 26in.
Fig. 98.—JOHNSON’S 7ft. 9in. “SINGLE” ENGINE,
MIDLAND RAILWAY
The new Midland single express engines are illustrated by Fig.
98. These locomotives have inside cylinders 19½in. diameter, with a
stroke of 26in. The driving wheels are 7ft. 9in. in diameter. By
standing on a railway station platform alongside one of these
engines, one gets a good idea of their immense proportions, the
abnormally high pitch of the boiler being especially noticeable.
Mr. Stroudley, in his “Gladstone” class of engines for the London,
Brighton and South Coast Railway, adopted an entirely opposite
practice. His engines had the leading and driving wheels coupled,
and a pair of smaller trailing wheels. The coupled wheels are 6ft. 6in.
diameter, and the trailing 4ft. 6in. diameter. The cylinders are inside,
and measure 18¼1in. diameter, the stroke being 26in.
The reversing apparatus is actuated by means of compressed air,
supplied by the Westinghouse brake pump; whilst part of the exhaust
steam is projected against the flanges of the leading wheels, and
upon condensation upon the flanges forms a lubricant to the flange
surface, when pressing against the inner sides of the rails. Fig. 99 is
from a photograph of “George A. Wallis,” an engine of the
“Gladstone” class.
Fig. 99.—“GEORGE A. WALLIS,” AN ENGINE OF
THE “GLADSTONE” CLASS, L.B. & S.C.R.
The “Tennant” (Fig. 100) class of express engines, on the North
Eastern Railway, deserves mention, being the design of a general
manager during the North Eastern locomotive interregnum of 1885.
The engines have four-coupled wheels, 7ft. diameter, and a
leading pair of small wheels, cylinders being 18in. diameter, and
24in. stroke.
The cab is somewhat similar to the Stirling pattern on the Great
Northern Railway.
The North British Railway engine, No. 592, was exhibited at the
Edinburgh Exhibition of 1886, and Mr. Holmes, her designer, was
awarded the gold medal.
The driving and trailing wheels are coupled, their diameter being
7ft. The fore part of the machine is supported on a four-wheeled
bogie. The symmetrical appearance of this and other North British
Railway locomotives is spoilt by having the safety valve located
above the dome casing. The cylinders are 18in. diameter, and 26in.
stroke. No. 602, another engine of this design, is notorious as being
the first engine to cross the Forth Bridge, when formally opened by
the Prince of Wales on March 4th, 1890, the Marchioness of
Tweeddale driving the engine upon the occasion.
Mr. Holmes, in 1890, introduced another very similar design of
North British Railway engines, but with coupled wheels only 6ft. 6in.
diameter. These are known as the “633” class, illustrated by Fig.
101.
Turning to the Great Eastern Railway, we have to chronicle some
types of locomotives designed by Mr. Holden. The express
passenger engines have a pair of small leading wheels and four-
coupled wheels of 7ft. diameter, with cylinders 18in. by 24in. The
valves are below the cylinders, which, by the way, are both cast in
one piece.
Fig. 100.—“1463,” N.E.R., ONE OF THE “TENNANT”
LOCOMOTIVES
In connection with this design of locomotive, the triumph of skilled
mechanism, combined with the application of scientific research,
deserves record, seeing that a troublesome waste product has been
turned into a valuable calorific agent. We refer to the introduction of
liquid fuel for locomotive purposes, as carried out under Mr. Holden’s
patent.
Fig. 101.—HOLMES’S TYPE OF EXPRESS
ENGINES FOR THE NORTH BRITISH
RAILWAY
Now, sanitary authorities have large powers, and they are very
fond of abusing these powers, and pushing matters to extreme
issues—although at times, as we know from personal experience,
they sometimes exceed their statutory powers, and find themselves
in a tight place from which they can only retreat by payment of
compensation and heavy law costs.
In connection with the pollution of streams the authorities have
very wide powers, and when they found the waters of the never clear
or limpid Channelsea and Lea were further polluted by some oily,
iridescent matter, with a pungent odour, the sanitary inspectors were
soon ferreting out the offenders. The waste products from the Great
Eastern Railway oil-gasworks at Stratford were found to be
responsible for the nuisance, and the service of a notice requiring
immediate abatement of the same was the result of the discovery.
Mr. Holden, remembering the good old proverb, “Necessity is the
mother of invention,” soon commenced to experiment with the matter
which the sanitary authorities refused to allow to be emptied into the
already impure waterways under their jurisdiction. The result of a
series of trials on, first a six-coupled tank engine, and then on a
single express, was a four-coupled express engine on the G.E.R.,
No. 760, named “Petrolea.”
This locomotive was constructed in 1886, and in general
appearance is similar to the four-coupled express engine just
described. The heating arrangements are, however, supplemented
by the liquid fuel burning apparatus, which may be briefly described
as follows: The oil fuel is carried on this engine in a rectangular tank
of 500 gallons capacity, but in later examples occupies two
cylindrical reservoirs, which contain 650 gallons, placed on the top of
the tender water-tanks, one on each side.
The liquid fuel is supplied to these reservoirs through man-holes
at the foot-plate end. The feed-pipes from these tanks unite on the
tender foot-plate at the centre, and from this junction the oil is
conveyed by the flexible hose pipe to the engine, where the supply is
again divided to feed the two burners situated on the fire-box front
just under the footboard.
Both the liquid in the tanks and the injected air are heated before
use, the former by means of steam coils in the tanks, and the latter
by coiled pipes in the smoke-box. The heated liquid fuel and air are
injected into the fire-box, through two nozzles in the form of fine
spray, steam being injected at the same moment through an outer
ring of the same nozzles. The steam divides the mixture of air and
liquid into such fine particles that it immediately ignites when in
contact with the incandescent coal and chalk fire already provided in
the fire-box. The fire-box is fitted with a brick arch deflector.
Fig. 102.—7ft. SINGLE ENGINE, G.E.R., FITTED
WITH HOLDEN’S LIQUID FUEL
APPARATUS
The whole of the apparatus is controlled by a four-way cock fitted
on the fire-box case, near the position usually occupied by the
regulator. The positions of the cock in question are: (1) steam to
warm coils in liquid fuel tank; (2) steam to ring-blowers on injectors;
(3) steam to centre jets of ejectors; and (4) steam to clear out the
liquid fuel pipes and ejectors. The success of “Petrolea” was so
apparent and unquestionable that Mr. Holden’s patent system of
burning liquid fuel was immediately fitted to other Great Eastern
Railway locomotives, with the result that at the present time a
number are fitted with his patent apparatus.
The following Great Eastern Railway locomotives have been
fitted to burn liquid fuel:—
9 four-wheel coupled express engines.
6 single express engines. (Fig. 102)
1 six-wheel coupled goods engine.
1 six-wheel coupled tank, and
20 four-wheel coupled bogie tanks.
and the 10 engines of the new class of “single” bogie expresses.
(Fig. 103.)
The application of the “Serve” corrugated tube has also been
introduced on the Great Eastern Railway in connection with the liquid
fuel. The goods engine and also two of the express passenger
engines have the “Serve” tubes. The experiment of burning liquid
fuel has been very successful, only 16lb. of oil having been
consumed per mile run, against an average of 35lb. of coal per mile,
with coal-fired engines.
Some very handsome Bogie Single Express Locomotives have
recently been built at the Stratford Works of the G.E.R. Company to
the designs of Mr. James Holden. They have been specially
constructed for running the fast Cromer traffic. The boiler has a
telescopic barrel 11ft. long, in two plates, and is 4ft. 3in. diameter
outside the smaller ring. It contains 227 tubes 1¾in. external
diameter, and the height of its centre line above the rail level is 7ft.
9in.
The fire-box is 7ft. long, and 4ft. ½ in. wide outside, and has a
grate area of 21.37 sq. ft., and is fired with oil fuel. The total heating
surface is 1,292.7 sq. ft., the tubes giving 1,178.5 sq. ft., and the fire-
box 114.2 sq. ft. The working pressure is 160 lbs. per sq. in.
The driving wheels are 7ft., the bogie wheels are 3ft. 9in., and the
trailing wheels 4ft. diameter. The total wheel base is 22ft. 9in., the
bogie wheels centres being 6ft. 6in. apart, from centre of bogie pin to
centre of driving wheel is 10ft. 6in., and from centre of driving wheel
to centre of trailing is 9ft. The total length of engine and tender, over
buffers, is 53ft. 3in.
The cylinders are 18in. diameter by 26in. stroke, the distance
between centres being 24in. The slide-valves are arranged
underneath, and are fitted with a small valve, which allows any water
that may collect in the slide-valve to drain off.
Fig. 103.—“No. 10,” THE LATEST TYPE OF G.E.R.
EXPRESS ENGINE, FIRED WITH LIQUID
FUEL
Steam sanding apparatus is fitted at front and back of the driving
wheels.
Macallan’s variable blast pipe is used, the diameter of the pipe
being 5¼in., and of the cap 4¾in.
This variable pipe is being adopted on all the Company’s
engines. The pipe has a hinged top, operated from the foot-plate.
When the hinged top is on the pipe, the area is that of a suitable
ordinary pipe, and when the top is moved off the area is about 30 per
cent. larger.
It is found that a large proportion of the work of the engines can
be done with the larger exhaust outlet, the result being a reduced
back pressure in the cylinders and also a reduced vacuum in the
smoke-box, and less disturbance of the fire and consequent saving
of fuel.
The tender is capable of carrying 2,790 gallons of water, 715
gallons of oil fuel, and 1½ tons of coal. It is provided with a water
scoop for replenishing the tank whilst running.
The weights of the engine and tender in working order are:
engine, 48½ tons; tender, 36 tons; total, 84½ tons.
The oil-firing arrangements embody a number of ingenious
details, among them the supply of hot air for combustion from a
series of cast-iron heaters placed around the inside of the smoke-
box, the air being drawn from the front through the heaters to the
burners for the exhausting action of the steam-jets used for injecting
the oil fuel. The latter is warmed before leaving the tender in a
cylindrical heating chamber, through which the exhaust steam from
the air-brake pump circulates.
The regulation of the oil supply is effected by a neatly designed
gear attached to the cover and hood of the ordinary fire-door, and
finally the burners or injectors are so constructed that should one
require cleaning, inspection, or renewal, the internal cones can all be
removed from the casing by simply unscrewing one large nut. These
engines have polished copper chimney tops, and are painted and
lined in the standard G.E.R. style, and fitted with the Westinghouse
automatic brake.
CHAPTER XIV.
Modern L.B. and S.C.R. locomotives—Four-coupled in front passenger tank—Six-coupled
tank with radial trailing wheels—Goods engines—“Bessemer,” four-coupled bogie
express—“Inspector”—Standard L.C. and D.R. passenger engines—Goods
locomotives—Three classes of tanks—Cambrian locomotives, passenger, goods, and
tank—S.E. engines—A “Prize Medal” locomotive—Stirling’s goods and tank engine—
His latest type of express engines—Adams’ locomotives on the L. & S.W.R.—Mixed
traffic engines—Passenger and six-coupled tanks—Drummond’s “Windcutter” smoke-
box—His four-cylinder express engine—North British passenger locomotives—Engines
for the West Highland Railway—Holme’s goods and tank engines—His latest express
type of engine—Classification of N.B.R. locomotives—N.B.R. inspection or cab engine
—L. and Y. locomotives—Aspinall’s water “pick-up” apparatus—Severe gradients on
the L. and Y. system—7ft. 3in. coupled expresses—“A” class of goods engines—
Standard tank engines—L. and Y. oil-burning tank locomotives—Caledonian Railway
engines—Drummond’s famous “Dunalastairs”—Excelled by his “Dunalastairs 2”—Six-
coupled “condensing” tender engines—“Carbrooke” class—Dimensions of 44 types of
Caledonian locomotives
The modern engines on the London, Brighton, and South Coast Railway are
designed by Mr. Billinton, and comprise—
The four-coupled in front tank with a trailing bogie, of which “Havant,” No. 363, is
an example. This engine was built at Brighton Works, 1897. Inside cylinders, 18in.
by 26in.; diameter of coupled wheels, 5ft. 6in. diameter. Heating surface, 1,189 sq.
ft. Steam pressure, 160lb. Weight in working order, 47 tons.
“Watersfield,” No. 457, built at Brighton in 1895, is a specimen of the six-coupled
goods tank engines, with radial trailing wheels. This class have inside cylinders,
18in. by 26in.; heating surface, 1,200 sq. ft.; diameter of wheels, 4ft. 6in.; steam
pressure 160lb.; weight in working order, 51 tons.
No. 449 represents the six-coupled goods tender engines, built by Vulcan
Foundry Co. in 1894, from Mr. Billinton’s designs. Inside cylinders, 18in. by 26in.;
wheels, 5ft. diameter; heating surface, 1,212 sq. ft.; steam pressure, 160lb.; weight
in working order: engine, 38 tons; tender, 25 tons.
“Bessemer,” No. 213, is one of the new type of four-coupled express passenger
engines, with leading bogie, and was built at Brighton Works, 1897. Inside cylinders,
18in. by 26in.; diameter of coupled wheels, 6ft. 9in.; heating surface, 1,342 sq. ft.;
working pressure, 170lb.; weight in working order: engine, 44 tons 14 cwt.; tender,
25 tons. Fig. 104 is from a photograph of “Goldsmith,” an engine of this class.
Before closing this short description of the London, Brighton, and South Coast
Railway locomotives, attention must be called to the combined engine and carriage
named “Inspector,” No. 481 (Fig. 105). This engine was constructed in 1869 by
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookfinal.com

More Related Content

Similar to An Introduction to Network Programming with Java 1st Edition Jan Graba (20)

DOCX
FRAUD DETECTION IN ONLINE AUCTIONING
Satish Chandra
 
PDF
Have You Ever Thought Where Java Is Used in Real World - Let's Know
Claritus Consulting
 
PDF
Have You Ever Thought Where Java is Used in Real World 2020
Claritus Consulting
 
PDF
Java Foundations Introduction To Program Design And Data Structures 2nd Editi...
eestissingar
 
PDF
Javatech An Introduction To Scientific And Technical Computing With Java Clar...
papaivierkiy
 
PPT
1.INTRODUCTION TO JAVA_2022 MB.ppt .
happycocoman
 
PDF
Data structures and_algorithms_in_java
Prabhu vip
 
PDF
Java application-development
Deepika Chaudhary
 
PPTX
The Java Story
David Parsons
 
PPT
Introduction to Computers, Programs, and Java
naimanighat
 
PPT
PPS Java Overview Unit I.ppt
CDSukte
 
PPT
PPS Java Overview Unit I.ppt
RajeshSukte1
 
PPTX
1_Introduction to Java.pptx java programming
amitraj53904
 
PPTX
MODULE_1_The History and Evolution of Java.pptx
VeerannaKotagi1
 
PDF
(eBook PDF) Java How to Program, Late Objects Global Edition 11th Edition
zcrowmatye
 
DOCX
Notes of java first unit
gowher172236
 
PDF
Java The Complete Reference Ninth Edition Herbert Schildt
ssuser36df07
 
PPT
Java
kavirishi
 
DOCX
java full 1.docx
SATHYAKALAKSKPRCASBS
 
DOCX
java full.docx
SATHYAKALAKSKPRCASBS
 
FRAUD DETECTION IN ONLINE AUCTIONING
Satish Chandra
 
Have You Ever Thought Where Java Is Used in Real World - Let's Know
Claritus Consulting
 
Have You Ever Thought Where Java is Used in Real World 2020
Claritus Consulting
 
Java Foundations Introduction To Program Design And Data Structures 2nd Editi...
eestissingar
 
Javatech An Introduction To Scientific And Technical Computing With Java Clar...
papaivierkiy
 
1.INTRODUCTION TO JAVA_2022 MB.ppt .
happycocoman
 
Data structures and_algorithms_in_java
Prabhu vip
 
Java application-development
Deepika Chaudhary
 
The Java Story
David Parsons
 
Introduction to Computers, Programs, and Java
naimanighat
 
PPS Java Overview Unit I.ppt
CDSukte
 
PPS Java Overview Unit I.ppt
RajeshSukte1
 
1_Introduction to Java.pptx java programming
amitraj53904
 
MODULE_1_The History and Evolution of Java.pptx
VeerannaKotagi1
 
(eBook PDF) Java How to Program, Late Objects Global Edition 11th Edition
zcrowmatye
 
Notes of java first unit
gowher172236
 
Java The Complete Reference Ninth Edition Herbert Schildt
ssuser36df07
 
Java
kavirishi
 
java full 1.docx
SATHYAKALAKSKPRCASBS
 
java full.docx
SATHYAKALAKSKPRCASBS
 

Recently uploaded (20)

PPTX
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
PPTX
Connecting Linear and Angular Quantities in Human Movement.pptx
AngeliqueTolentinoDe
 
PPTX
Aerobic and Anaerobic respiration and CPR.pptx
Olivier Rochester
 
PPTX
Ward Management: Patient Care, Personnel, Equipment, and Environment.pptx
PRADEEP ABOTHU
 
PDF
Quiz Night Live May 2025 - Intra Pragya Online General Quiz
Pragya - UEM Kolkata Quiz Club
 
PPTX
Parsing HTML read and write operations and OS Module.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
PDF
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
PDF
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
PPTX
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
PDF
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
DOCX
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
PPTX
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
PPT
21st Century Literature from the Philippines and the World QUARTER 1/ MODULE ...
isaacmendoza76
 
PDF
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
PDF
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
Connecting Linear and Angular Quantities in Human Movement.pptx
AngeliqueTolentinoDe
 
Aerobic and Anaerobic respiration and CPR.pptx
Olivier Rochester
 
Ward Management: Patient Care, Personnel, Equipment, and Environment.pptx
PRADEEP ABOTHU
 
Quiz Night Live May 2025 - Intra Pragya Online General Quiz
Pragya - UEM Kolkata Quiz Club
 
Parsing HTML read and write operations and OS Module.pptx
Ramakrishna Reddy Bijjam
 
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
21st Century Literature from the Philippines and the World QUARTER 1/ MODULE ...
isaacmendoza76
 
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
Ad

An Introduction to Network Programming with Java 1st Edition Jan Graba

  • 1. An Introduction to Network Programming with Java 1st Edition Jan Graba download pdf https://ebookfinal.com/download/an-introduction-to-network-programming- with-java-1st-edition-jan-graba/ Visit ebookfinal.com today to download the complete set of ebook or textbook!
  • 2. Here are some recommended products that we believe you will be interested in. You can click the link to download. Simply Java An Introduction to Java Programming Programming Series 1st Edition James Levenick https://ebookfinal.com/download/simply-java-an-introduction-to-java- programming-programming-series-1st-edition-james-levenick/ Java An Introduction to Problem Solving and Programming 7th Edition Walter Savitch https://ebookfinal.com/download/java-an-introduction-to-problem- solving-and-programming-7th-edition-walter-savitch/ Introduction to Java Programming Comprehensive Version 6th Edition Liang https://ebookfinal.com/download/introduction-to-java-programming- comprehensive-version-6th-edition-liang/ An introduction to programming with Mathematica 3rd Edition Paul R. Wellin https://ebookfinal.com/download/an-introduction-to-programming-with- mathematica-3rd-edition-paul-r-wellin/
  • 3. Wireless Java Programming with J2ME 1st Edition Yu Feng https://ebookfinal.com/download/wireless-java-programming- with-j2me-1st-edition-yu-feng/ Beginning Programming with Java For Dummies Third Edition Barry Burd https://ebookfinal.com/download/beginning-programming-with-java-for- dummies-third-edition-barry-burd/ An Introduction to Stata Programming 2nd Edition Christopher F. Baum https://ebookfinal.com/download/an-introduction-to-stata- programming-2nd-edition-christopher-f-baum/ Introduction to 3D game programming with DirectX 10 1st Edition Frank D. Luna https://ebookfinal.com/download/introduction-to-3d-game-programming- with-directx-10-1st-edition-frank-d-luna/ Beginning Java 8 APIs Extensions and Libraries Swing JavaFX JavaScript JDBC and Network Programming APIs 1st Edition Kishori Sharan https://ebookfinal.com/download/beginning-java-8-apis-extensions-and- libraries-swing-javafx-javascript-jdbc-and-network-programming- apis-1st-edition-kishori-sharan/
  • 5. An Introduction to Network Programming with Java 1st Edition Jan Graba Digital Instant Download Author(s): Jan Graba ISBN(s): 9780321116147, 0321116143 Edition: 1 File Details: PDF, 2.62 MB Year: 2007 Language: english
  • 6. An Introduction to Network Programming with Java
  • 7. Jan Graba An Introduction to Network Programming with Java
  • 8. Jan Graba, BA, PGCE, MSc Faculty of ACES Sheffield Hallam University UK British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library Library of Congress Control Number: 2006923894 ISBN-10: 1-84628-380-9 ISBN-13: 978-1-84628-380-2 Printed on acid-free paper © Jan Graba 2007 New and revised edition of An Introduction to Network Programming with Java published by Addison Wesley, 2003, ISBN 0321116143 Sun, Sun Microsystems, the Sun Logo, the Java programming language, J2SE 5.0, and JavaBeans are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Microsoft, Encarta, MSN, and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Apart from any fair dealing for the purposes of research or private study, or criticism or review, as permitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced, stored or transmitted, in any form or by any means, with the prior permission in writing of the publish- ers, or in the case of reprographic reproduction in accordance with the terms of licences issued by the Copyright Licensing Agency. Enquiries concerning reproduction outside those terms should be sent to the publishers. The use of registered names, trademarks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant laws and regulations and therefore free for general use. The publisher makes no representation, express or implied, with regard to the accuracy of the information contained in this book and cannot accept any legal responsibility or liability for any errors or omissions that may be made. Whilst we have made considerable efforts to contact all holders of copyright material contained in this book, we may have failed to locate some of them. Should holders wish to contact the Publisher, we will be happy to come to some arrangement with them. Printed in the United States of America (SB) 9 8 7 6 5 4 3 2 1 Springer Science+Business Media, LLC springer.com
  • 9. Preface The market in general-purpose Java texts is an exceptionally well populated one, as can be seen from just a cursory examination of the programming language section of any major bookshop. Surprisingly, the market in Java network programming texts is a much less exploited one, featuring very few texts. It is true that the better general- purpose Java texts provide some guidance on aspects of network programming, but this almost invariably takes the form of rather superficial coverage, often relegated to the end of the particular text and offering little more than an outline of the relevant concepts. Even those few texts that are devoted specifically to network programming in Java (and one or two are very good indeed) are rather thick tomes that are probably of greatest use as reference texts. The truth of this assertion appears to be reinforced by the absence of practical exercises from such texts. When I began work on the first edition of this work, my declared intention was to write a more 'streamlined' work that could serve equally as the core text on an undergraduate module and as the quick, clear, 'no-nonsense' guide required by a busy IT professional. Numerous examples and associated screenshots were provided, with the examples 'stripped down' to their bare essentials in order to avoid overwhelming the reader with too much detail. There is, of course, a level of detail below which it is impossible to go without omitting some of the essentials and this led to a few examples running over multiple pages. However, a conscious effort was made to keep this to a minimum and to provide adequate program comments where this did occur. It was gratifying to find that the first edition was well received, but the time has now come to replace it with an updated version. The changes in this second edition fall into three categories: • language changes, largely reflecting the significant changes introduced by J2SE 5.0 (but also including one or two changes brought in by earlier versions of Java); • the updating of support software, particularly that used for Web applications; • new material, some related to the changes introduced by J2SE 5.0 (otherwise known as Java 5) and some extending earlier coverage. A summary of the major elements of these changes is given below. Language Changes These mostly affect the example programs and the model solutions provided on the associated Web site. However, there are occasional, passing references to some of these new features in the main body of the text where it is considered appropriate. The main language changes introduced are listed below. • Replacement of the BufferedReader+InputStreamReader combination with the single Scanner class, with consequent erradication of the need to use the
  • 10. vi An Introduction to Network Programming with Java type 'wrapper' classes to convert String input into numeric values (a major improvement on the traditional method for obtaining input). • Associated with the above, replacement of the BufferedReader+FileReader combination with Scanner+File and that of the PrintWriter+FileWriter combination with PrintWriter+File for serial disc file I/O. • Replacement of the cumbersome addWindowListener(new WindowAdapter... method for closing down GUI applications with setDefaultCloseOperation(EXIT_ON_CLOSE). (This had been available since J2SE 1.3, but had deliberately not been included in the original text due to the earlier method being the one still used by most people at that time.) • The formatting of numeric output (particularly decimal output) via method printf. • The inclusion of generics in the declaration of Vectors, with the associated 'auto-boxing' and 'auto-unboxing' of elements. • Introduction of the 'enhanced for' loop where appropriate. Updating of Support Software • Replacement of the JSWDK Web server with Apache Tomcat. • Replacement of the JavaBean Development Kit (BDK) with the Bean Builder for the testing of JavaBeans. • Removal of the section on the now defunct HTMLConverter utility and updating of the example browsers to Internet Explorer 6 and Firefox 1.5. New Material • Coverage of non-blocking I/O (introduced in J2SE 1.4), but retaining coverage of the more traditional blocking I/O. • The use of JDBC with the DataSource interface (also introduced in J2SE 1.4), but maintaining coverage of the more traditional DriverManager class approach. The associated examples are no longer confined to the use of MS Access, but have been extended to include MySQL. The significant advantages to large-scale, commercial databases of using DataSource in preference to DriverManager are made clear to the reader. • As part of good practice, the above DataSource technique makes use of a DAO (Data Access Object) to encapsulate access to the database, so that data manipulation code is separated from business logic. On the CD-ROM accompanying this text may be found the executable file for installing J2SE 5.0 onto MS Windows platforms (available via free download from the Sun site, of course). In addition to this, the CD contains all example code and several media files (the latter for use with material in the final two chapters). Model solutions for end-of-chapter exercises are accessible by lecturers and other authorised individuals from the companion Web site (accessible via http://homepage.ntlworld.com/jan.graba/javanet.html). Finally, there is a document entitled Java Environment Installation that provides downloading and installation
  • 11. Preface vii instructions for those additional software elements for which permission for inclusion on the CD was not forthcoming. This document also contains installation instructions (and downloading instructions, which shouldn't be required) for J2SE 5.0 itself. I sincerely hope that your programming experiences while using this text give you some of the sense of satisfaction that I have derived from writing it. Of course, along with such satisfaction comes the occasional (?) infuriating sense of frustration when things just won't work, but you wouldn't want things to be too easy ... would you?? :-) Jan 22nd Feb 2006
  • 12. Contents Chapter 1 Basic Concepts, Protocols and Terminology ......................... 1 1.1 Clients, Servers and Peers ................................................................. 1 1.2 Ports and Sockets .............................................................................. 2 1.3 The Internet and IP Addresses .......................................................... 3 1.4 Internet Services, URLs and DNS .................................................... 4 1.5 TCP ................................................................................................... 5 1.6 UDP .................................................................................................. 7 Chapter 2 Starting Network Programming in Java ............................... 9 2.1 The InetAddress Class ...................................................................... 9 2.2 Using Sockets ................................................................................... 12 2.2.1 TCP Sockets ..... .................................................................... 12 2.2.2 Datagram (UDP) Sockets ....................................................... 18 2.3 Network Programming with GUIs ................................................... 28 2.4 Downloading Web Pages ................................................................. 37 Exercises ................................................................................................... 41 Chapter 3 Multithreading and Multiplexing .......................................... 51 3.1 Thread Basics ................................................................................... 51 3.2 Using Threads in Java ..................................................................... 52 3.2.1 Extending the Thread Class ................................................... 53 3.2.2 Explicitly Implementing the Runnable Interface ...................... 57 3.3 Multithreaded Servers ..................................................................... 60 3.4 Locks and Deadlock ........................................................................ 65 3.5 Synchronising Threads .................................................................... 67 3.6 Non-Blocking Servers ..................................................................... 74 3.6.1 Overview ................................................................................. 74 3.6.2 Implementation ......................................................................... 76 3.6.3 Further Details .......................................................................... 86 Exercises .................................................................................................. 88 Chapter 4 File Handling .......................................................................... 91 4.1 Serial Access Files .......................................................................... 91 4.2 File Methods ................................................................................... 97 4.3 Redirection .................................................................................... 99 4.4 Command Line Parameters ............................................................ 101 4.5 Random Access Files ..................................................................... 102 4.6 Serialisation .................................................................................... 109 4.7 File I/O with GUIs ......................................................................... 113 4.8 Vectors ........................................................................................... 120 4.9 Vectors and Serialisation ............................................................... 123
  • 13. Contents ix Exercises ................................................................................................. 132 Chapter 5 Remote Method Invocation (RMI) ...................................... 136 5.1 The Basic RMI Process .................................................................. 136 5.2 Implementation Details .................................................................. 137 5.3 Compilation and Execution ............................................................ 141 5.4 Using RMI Meaningfully ............................................................... 143 5.5 RMI Security .................................................................................. 153 Exercises ................................................................................................. 156 Chapter 6 CORBA ................................................................................... 158 6.1 Background and Basics ................................................................... 158 6.2 The Structure of a Java IDL Specification ...................................... 159 6.3 The Java IDL Process ...................................................................... 163 6.4 Using Factory Objects ..................................................................... 173 6.5 Object Persistence ........................................................................... 184 6.6 RMI-IIOP ........................................................................................ 184 Exercises .................................................................................................. 186 Chapter 7 Java Database Connectivity (JDBC) ................................... 188 7.1 The Vendor Variation Problem ....................................................... 188 7.2 SQL and Versions of JDBC ............................................................ 189 7.3 Creating an ODBC Data Source ..................................................... 190 7.4 Simple Database Access .................................................................. 191 7.5 Modifying the Database Contents ................................................... 199 7.6 Transactions .................................................................................... 203 7.7 Meta Data ........................................................................................ 204 7.8 Using a GUI to Access a Database ................................................. 207 7.9 Scrollable ResultSets in JDBC 2.0 .................................................. 210 7.10 Modifying Databases via Java Methods ......................................... 215 7.11 Using the DataSource Interface ...................................................... 220 7.11.1 Overview and Support Software ............................................ 220 7.11.2 Defining a JNDI Resource Reference ....................................... 222 7.11.3 Mapping the Resource Reference onto a Real Resource ........... 223 7.11.4 Obtaining the Data Source Connection ..................................... 225 7.11.5 Data Access Objects .................................................................. 226 Exercises .................................................................................................. 232 Chapter 8 Servlets .................................................................................... 234 8.1 Servlet Basics .................................................................................... 234 8.2 Setting up the Servlet API ............................................................... 235 8.3 Creating a Web Application ............................................................ 237 8.4 The Servlet URL and the Invoking Web Page ................................ 239 8.5 Servlet Structure ............................................................................... 240 8.6 Testing a Servlet .............................................................................. 242 8.7 Passing Data .................................................................................... 242
  • 14. x An Introduction to Network Programming with Java 8.8 Sessions ........................................................................................... 249 8.9 Cookies ............................................................................................ 260 8.10 Accessing a Database Via a Servlet ................................................ 268 Exercises .................................................................................................. 275 Chapter 9 JavaServer Pages (JSPs) ........................................................ 278 9.1 The Rationale behind JSPs ............................................................... 278 9.2 Compilation and Execution ............................................................. 279 9.3 JSP Tags .......................................................................................... 280 9.4 Implicit JSP Objects ........................................................................ 283 9.5 Collaborating with Servlets ............................................................. 285 9.6 JSPs in Action ................................................................................. 285 9.7 Error Pages ...................................................................................... 291 9.8 Using JSPs to Access Remote Databases ....................................... 294 Exercises .................................................................................................. 295 Chapter 10 JavaBeans ................................................................................ 297 10.1 Introduction to the Bean Builder .................................................... 298 10.2 Creating a JavaBean ....................................................................... 301 10.3 Exposing a Bean's Properties ......................................................... 307 10.4 Making Beans Respond to Events ................................................. 311 10.5 Using JavaBeans within an Application ........................................ 315 10.6 Bound Properties ........................................................................... 317 10.7 Using JavaBeans in JSPs ............................................................... 324 10.7.1 The Basic Procedure ........................................................ 324 10.7.2 Calling a Bean's Methods Directly .................................. 326 10.7.3 Using HTML Tags to Manipulate a Bean's Properties .... 330 Exercises .................................................................................................. 342 Chapter 11 Introduction to Enterprise JavaBeans ................................. 345 11.1 Categories of EJB ........................................................................... 345 11.2 Basic Structure of an EJB ............................................................... 346 11.3 Packaging and Deployment ............................................................ 349 11.4 Client Programs .............................................................................. 351 11.5 Entity EJBs ..................................................................................... 353 Chapter 12 Multimedia ............................................................................. 359 12.1 Transferring and Displaying Images Easily ................................... 360 12.2 Transferring Media Files ................................................................ 365 12.3 Playing Sound Files ....................................................................... 370 12.4 The Java Media Framework ........................................................... 372 Exercises ................................................................................................. 379 Chapter 13 Applets ................................................................................... 380 13.1 Applets and JApplets ...................................................................... 380
  • 15. Contents xi 13.2 Applet Basics and the Development Process ................................. 381 13.3 The Internal Operation of Applets .................................................. 385 13.4 Using Images in Applets ................................................................ 392 13.4.1 Using Class Image ........................................................... 392 13.4.2 Using Class ImageIcon .................................................... 397 13.5 Scaling Images ................................................................................ 400 13.6 Using Sound in Applets .................................................................. 401 Exercises .................................................................................................. 405 Appendix A Structured Query Language (SQL) ............................. 406 Appendix B Deployment Descriptors for EJBs ................................ 411 Appendix C Further Reading ............................................................. 414 Index ............................................................................................................. 417
  • 16. 1 Basic Concepts, Protocols and Terminology Learning Objectives After reading this chapter, you should: • have a high level appreciation of the basic means by which messages are sent and received on modern networks; • be familiar with the most important protocols used on networks; • understand the addressing mechanism used on the Internet; • understand the basic principles of client/server programming. The fundamental purpose of this opening chapter is to introduce the underpinning network principles and associated terminology with which the reader will need to be familiar in order to make sense of the later chapters of this book. The material covered here is entirely generic (as far as any programming language is concerned) and it is not until the next chapter that we shall begin to consider how Java may be used in network programming. If the meaning of any term covered here is not clear when that term is later encountered in context, the reader should refer back to this chapter to refresh his/her memory. It would be very easy to make this chapter considerably larger than it currently is, simply by including a great deal of dry, technical material that would be unlikely to be of any practical use to the intended readers of this book. However, this chapter is intentionally brief, the author having avoided the inclusion of material that is not of relevance to the use of Java for network programming. The reader who already has a sound grasp of network concepts may safely skip this chapter entirely. 1.1 Clients, Servers and Peers The most common categories of network software nowadays are clients and servers. These two categories have a symbiotic relationship and the term client/server programming has become very widely used in recent years. It is important to distinguish firstly 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 significant 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 specifically 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
  • 17. 2 An Introduction to Network Programming with Java (by Web servers) and the downloading of files 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 Netscape Communicator or Microsoft Explorer). Though a client and its corresponding server will normally run on different machines in a real-world application, it is perfectly possible for such programs 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 final testing on separate machines). This avoids the need for multiple machines and multiple testing personnel. 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 intermediary, 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. 1.2 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 hardware 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 connection) and is identified by a number in the range 1-65535. This number has no correspondence with the number of physical connections to the computer, of which there may be only one (even though the number of ports used on that machine may be much greater than this). Ports are implemented upon all computers attached to a network, but it is only those machines that have server programs running on them for which the network programmer will refer explicitly to port numbers. Each port may be dedicated to a particular server/service (though the number of available ports will normally greatly exceed the number that is actually used). Port numbers in the range 1-1023 are normally set aside for the use of specified standard services, often referred to as 'well-known' services. For example, port 80 is normally used by Web servers. Some of the more common well-known services are listed in Section 1.4. Application programs wishing to use ports for non-standard services should avoid using port numbers 1-1023. (A range of 1024-65535 should be more than enough for even the most prolific of network programmers!)
  • 18. Basic Concepts, Protocols and Terminology 3 For each port supplying a service, there is a server program waiting for any requests. All such programs run together in parallel on the host machine. When a client attempts to make connection with a particular server program, it supplies the port number of the associated service. The host machine examines the port number and passes the client’s transmission to the appropriate server program for processing. In most applications, of course, there are likely to be multiple clients wanting the same service at the same time. A common example of this requirement is that of multiple browsers (quite possibly thousands of them) wanting Web pages from the same server. The server, of course, needs some way of distinguishing between clients and keeping their dialogues separate from each other. This is achieved via the use of sockets. As stated earlier, a socket is an abstract concept and not an element of computer hardware. It is used to indicate one of the two end-points of a communication link between two processes. When a client wishes to make connection to a server, it will create a socket at its end of the communication link. Upon receiving the client's initial request (on a particular port number), the server will create a new socket at its end that will be dedicated to communication with that particular client. Just as one hardware link to a server may be associated with many ports, so too may one port be associated with many sockets. More will be said about sockets in Chapter 2. 1.3 The Internet and IP Addresses An internet (lower-case 'i') is a collection of computer networks that allows any computer on any of the associated networks to communicate with any other computer located on any of the other associated networks (or on the same network, of course). The protocol used for such communication is called the Internet Protocol (IP). The Internet (upper-case 'I') is the world's largest IP-based network. Each computer on the Internet has a unique IP address, the current version of which is IPv4 (Internet Protocol version 4). This represents machine addresses in what is called quad notation. This is made up of four eight-bit numbers (i.e., numbers in the decimal range 0-255), separated by dots. For example, 131.122.3.219 would be one such address. Due to a growing shortage of IPv4 addresses, IPv4 is due to be replaced with IPv6, the draft standard for which was published on the 10th of August, 1998. IPv6 uses 128-bit addresses, which provide massively more addresses. Many common Internet applications already work with IPv6 and it is expected that IPv6 will gradually replace IPv4, with the two coexisting for a number of years during a transition period. Recent years have witnessed an explosion in the growth and use of the Internet. As a result, there has arisen a need for a programming language with features designed specifically for network programming. Java provides these features and does so in a platform-independent manner, which is vital for a heterogeneous network such as the Internet. Java is sometimes referred to as 'the language of the Internet' and it is the use of Java in this context that has had a major influence on the popularisation of the language. For many programmers, the need to program for the Internet is one of the main reasons, if not the reason, for learning to program in Java.
  • 19. 4 An Introduction to Network Programming with Java 1.4 Internet Services, URLs and DNS Whatever the service provided by a server, there must be some established protocol governing the communication that takes place between server and client. Each end of the dialogue must know what may/must be sent to the other, the format in which it should be sent, the sequence in which it must be sent (if sequence matters) and, for 'open-ended' dialogues, how the dialogue is to be terminated. For the standard services, such protocols are made available in public documents, usually by either the Internet Engineering Task Force (IETF) or the World Wide Web Consortium (W3C). Some of the more common services and their associated ports are shown in Figure 1.1. For a more esoteric or 'bespoke' service, the application writer must establish a protocol and convey it to the intended users of that service. Protocol name Port number Nature of service Echo 7 The server simply echoes the data sent to it. This is useful for testing purposes. Daytime 13 Provides the ASCII representation of the current date and time on the server. FTP-data 20 Transferring files. (FTP uses two ports.) FTP 21 Sending FTP commands like PUT and GET. Telnet 23 Remote login and command line interaction. SMTP 25 E-mail. (Simple Mail Transfer Protocol.) HTTP 80 HyperText Transfer Protocol (the World Wide Web protocol). NNTP 119 Usenet. (Network News Transfer Protocol.) Table 1.1 Some well-known network services. A URL (Uniform Resource Locator) is a unique identifier for any resource located on the Internet. It has the following structure (in which BNF notation is used): <protocol>://<hostname>[:<port>][/<pathname>][/<filename>[#<section>]] For example: http://java.sun.com/j2se/1.5.0/download.jsp
  • 20. Basic Concepts, Protocols and Terminology 5 For a well-known protocol, the port number may be omitted and the default port number will be assumed. Thus, since the example above specifies the HTTP protocol (the protocol of the Web) and does not specify on which port of the host machine the service is available, it will be assumed that the service is running on port 80 (the default port for Web servers). If the file name is omitted, then the server sends a default file from the directory specified in the path name. (This default file will commonly be called index.html or default.html.) The 'section' part of the URL (not often specified) indicates a named 'anchor' in an HTML document. For example, the HTML anchor in the tag <A NAME="thisPlace"></A> would be referred to as thisPlace by the section component of the URL. Since human beings are generally much better at remembering meaningful strings of characters than they are at remembering long strings of numbers, the Domain Name System was developed. A domain name, also known as a host name, is the user-friendly equivalent of an IP address. In the previous example of a URL, the domain name was java.sun.com. The individual parts of a domain name don't correspond to the individual parts of an IP address. In fact, domain names don't always have four parts (as IPv4 addresses must have). Normally, human beings will use domain names in preference to IP addresses, but they can just as well use the corresponding IP addresses (if they know what they are!). The Domain Name System provides a mapping between IP addresses and domain names and is held in a distributed database. The IP address system and the DNS are governed by ICANN (the Internet Corporation for Assigned Names and Numbers), which is a non-profitmaking organisation. When a URL is submitted to a browser, the DNS automatically converts the domain name part into its numeric IP equivalent. 1.5 TCP In common with all modern computer networks, the Internet is a packet-switched network, which means that messages between computers on the Internet are broken up into blocks of information called packets, with each packet being handled separately and possibly travelling by a completely different route from that of other such packets from the same message. IP is concerned with the routing of these packets through an internet. Introduced by the American military during the Cold War, it was designed from the outset to be robust. In the event of a military strike against one of the network routers, the rest of the network had to continue to function as normal, with messages that would have gone through the damaged router being re-routed. IP is responsible for this re-routing. It attaches the IP address of the intended recipient to each packet and then tries to determine the most efficient route available to get to the ultimate destination (taking damaged routers into account). However, since packets could still arrive out of sequence, be corrupted or even not arrive at all (without indication to either sender or intended recipient that
  • 21. 6 An Introduction to Network Programming with Java anything had gone wrong), it was decided to place another protocol layer on top of IP. This further layer was provided by TCP (Transmission Control Protocol), which allowed each end of a connection to acknowledge receipt of IP packets and/or request retransmission of lost or corrupted packets. In addition, TCP allows the packets to be rearranged into their correct sequence at the receiving end. IP and TCP are the two commonest protocols used on the Internet and are almost invariably coupled together as TCP/IP. TCP is the higher level protocol that uses the lower level IP. For Internet applications, a four-layer model is often used, which is represented diagrammatically in Figure 1.1 below. The transport layer will often comprise the TCP protocol, but may be UDP (described in the next section), while the internet layer will always be IP. Each layer of the model represents a different level of abstraction, with higher levels representing higher abstraction. Thus, although applications may appear to be communicating directly with each other, they are actually communicating directly only with their transport layers. The transport and internet layers, in their turn, communicate directly only with the layers immediately above and below them, while the host-to-network layer communicates directly only with the IP layer at each end of the connection. When a message is sent by the application layer at one end of the connection, it passes through each of the lower layers. As it does so, each layer adds further protocol data specific to the particular protocol at that level. For the TCP layer, this process involves breaking up the data packets into TCP segments and adding sequence numbers and checksums; for the IP layer, it involves placing the TCP segments into IP packets called datagrams and adding the routing details. The host-to-network layer then converts the digital data into an analogue form suitable for transmission over the carrier wire, sends the data and converts it back into digital form at the receiving end. Figure 1.1 The 4-Layer Network Model At the receiving end, the message travels up through the layers until it reaches the receiving application layer. As it does so, each layer converts the message into a form suitable for receipt by the next layer (effectively reversing the corresponding process carried out at the sending end) and carries out checks appropriate to its own Application Layer Internet Layer (IP) Internet Layer (IP) Application Layer Transport Layer (E.g., TCP) Transport Layer (E.g., TCP) path Logical Host-to-network layer
  • 22. Basic Concepts, Protocols and Terminology 7 protocol. If recalculation of checksums reveals that some of the data has been corrupted or checking of sequence numbers shows that some data has not been received, then the transport layer requests re-transmission of the corrupt/missing data. Otherwise, the transport layer acknowledges receipt of the packets. All of this is completely transparent to the application layer. Once all the data has been received, converted and correctly sequenced, it is presented to the recipient application layer as though that layer had been in direct communication with the sending application layer. The latter may then send a response in exactly the same manner (and so on). In fact, since TCP provides full duplex transmission, the two ends of the connection may be sending data simultaneously. The above description has deliberately hidden many of the low-level details of implementation, particularly the tasks carried out by the host-to-network layer. In addition, of course, the initial transmission may have passed through several routers and their associated layers before arriving at its ultimate destination. However, this high-level view covers the basic stages that are involved and is quite sufficient for our purposes. Another network model that is often referred to is the seven-layer Open Systems Interconnection (OSI) model. However, this model is an unnecessarily complex one for our purposes and is better suited to non-TCP/IP networks anyway. 1.6 UDP Most Internet applications use TCP as their transport mechanism. Unfortunately, the checks built into TCP to make it such a robust protocol do not come without a cost. The overhead of providing facilities such as confirmation of receipt and re- transmission of lost or corrupted packets means that TCP is a relatively slow transport mechanism. For many applications (e.g., file transfer), this does not really matter greatly. For these applications, it is much more important that the data arrives intact and in the correct sequence, both of which are guaranteed by TCP. For some applications, however, these factors are not the most important criteria and the relatively slow throughput speed provided by TCP is simply not feasible. Such applications include the playing of audio and video while the associated files are being downloaded, via what is called streaming. One of the most popular streaming technologies is called RealAudio. RealAudio does not use TCP, because of its large overhead. This and other such applications use User Datagram Protocol (UDP). UDP is an unreliable protocol, since: • it doesn't guarantee that each packet will arrive; • it doesn't guarantee that packets will be in the right order. UDP doesn't re-send a packet if it is missing or there is some other error, and it doesn't assemble packets into the correct order. However, it is significantly faster than TCP. For applications such as the streaming of audio or video, losing a few bits of data is much better than waiting for re-transmission of the missing data. The major objective in these two applications is to keep playing the sound/video without
  • 23. 8 An Introduction to Network Programming with Java interruption. In addition, it is possible to build error-checking code into the UDP data streams to compensate for the missing data.
  • 24. 2 Starting Network Programming in Java Learning Objectives After reading this chapter, you should : • know how to determine the host machine's IP address via a Java program; • know how to use TCP sockets in both client programs and server programs; • know how to use UDP sockets in both client programs and server programs; • appreciate the convenience of Java's stream classes and the consistency of the interface afforded by them; • appreciate the ease with which GUIs can be added to network programs; • know how to check whether ports on a specified machine are running services; • know how to use Java to render Web pages. Having covered fundamental network protocols and techniques in a generic fashion in Chapter 1, it is now time to consider how those protocols may be used and the techniques implemented in Java. Core package java.net contains a number of very useful classes that allow programmers to carry out network programming very easily. Package javax.net, introduced in J2SE 1.4, contains factory classes for creating sockets in an implementation-independent fashion. Using classes from these packages (primarily from the former), the network programmer can communicate with any server on the Internet or implement his/her own Internet server. 2.1 The InetAddress Class One of the classes within package java.net is called InetAddress, which handles Internet addresses both as host names and as IP addresses. Static method getByName of this class uses DNS (Domain Name System) to return the Internet address of a specified host name as an InetAddress object. In order to display the IP address from this object, we can simply use method println (which will cause the object's toString method to be executed). Since method getByName throws the checked exception UnknownHostException if the host name is not recognised, we must either throw this exception or (preferably) handle it with a catch clause. The following example illustrates this.
  • 25. 10 An Introduction to Network Programming with Java Example import java.net.*; import java.util.*; public class IPFinder { public static void main(String[] args) { String host; Scanner input = new Scanner(System.in); System.out.print("nnEnter host name: "); host = input.next(); try { InetAddress address = InetAddress.getByName(host); System.out.println("IP address: " + address.toString()); } catch (UnknownHostException uhEx) { System.out.println("Could not find " + host); } } } The output from a test run of this program is shown in Figure 2.1. Figure 2.1 Using method getByName to retrieve IP address of a specified host.
  • 26. Random documents with unrelated content Scribd suggests to you:
  • 27. Mr. A. M. Watkin became locomotive superintendent of the South Eastern Railway in 1876, and he introduced a very pretty design of express passenger engines. Twenty engines of the type were constructed: Nos. 259 to 268 by Sharp, Stewart, and Co., and Nos. 269 to 278 by the Avonside Engine Company. Inside frames were provided; the leading wheels were 4ft. and the four-coupled wheels 6ft. 6in. diameter. The cylinders were 17in. diameter and 24in. stroke. The weight in working order was 34½ tons; the total heating surface, 1,103½ sq. ft. The splashers to the coupled wheels were of open-work design. The chimney was of the rimless South Eastern pattern; a dome was provided on the centre of the boiler barrel, and a duplex safety valve on the fire-box top. A cab very much resembling the standard London and North Western Railway pattern was fitted to the engines. Several of these engines, as rebuilt by Mr. Stirling, remain in work at the present time; they are principally employed on the Mid-Kent services. In 1874 Mr. Stroudley, the then locomotive superintendent of the London, Brighton and South Coast Railway, built the “Grosvenor” with 6ft. 9in. single driving wheels, inside cylinders 17in. by 24in., and a total heating surface of 1,132 sq. ft. The “Stroudley” speed indicator was fitted to this engine. On August 13th, 1876, the “Grosvenor” conveyed a train from Victoria to Portsmouth (87 miles) without a stop. This was the first occasion on which such a trip had been performed; the time taken was 110 minutes. No other engine exactly similar to the “Grosvenor” was constructed; but in 1877 the “Abergavenny”—with 6ft. 6in. single drivers and cylinders 16in. by 22in.—was built, and in 1880 the first of the “G” class of singles was turned out at the Brighton Works. These also have single driving wheels 6ft. 6in. in diameter, but the cylinders are 17in. diameter, the stroke being 24in. The weight on the driving wheel is 13 tons. An interesting era in the evolution of the steam locomotive is at this point arrived at—viz., the first really practical trial of compound
  • 28. engines, or the use of steam twice over for the purpose of propelling a locomotive. To Mr. Webb, the chief mechanical engineer of the London and North Western Railway, is due the honour of introducing the compound system on an extended scale in railway practice. Although 21 years have now passed since the premier attempt of giving the system a fair trial on an English railway was made, it does not seem to have gained much favour with English locomotive engineers. Indeed, at the present time, excepting a few minor trials elsewhere, the London and North Western Railway is the only company that constructs and uses compound locomotives. Mr. Webb employs the three-cylinder type of engine, which is an adaptation of the system introduced by M. Mallet on the Bayonne and Biarritz Railway. Three engines were built from Mr. Mallet’s design by Schneider and Co., Creusot, and were brought into use in July, 1876. In these locomotives Mallet employed two outside cylinders, one being 15¾in. and the other 9½in. diameter. Mr. Webb uses three cylinders: an inside cylinder for the l.p. steam and two outside cylinders for the high-pressure steam. But at first one of Trevithick’s old “single” engines was fitted up on Mallet’s two-cylinder plan. This was in 1878. The engine worked successfully for five years on the Ashley and Nuneaton branch of the London and North Western Railway, and thereupon Mr. Webb decided to construct compound engines on his three-cylinder system. The first of such engines was the “Experiment.” Her outside h.p. cylinders were 11½in. diameter, the inside l.p. being 26in. diameter. Joy’s celebrated valve gear was employed to regulate the admission of steam to the cylinders. “Webb” compounds have two pairs of driving wheels, but these are uncoupled, so that practically the engines are “singles.” Whether the four driving wheels work well together, or whether, on the other hand, there exists a considerable amount of either slip or skidding is another matter. The trailing pair of wheels is driven from the h.p. cylinders, and the middle pair from the inside or l.p. cylinder.
  • 29. Mr. Bowen-Cooke, an authority on London and North Western Railway locomotive practice, sums up the advantages of the “Webb” compound system under the five following heads:— 1. Greater power. 2. Economy in the consumption of fuel. 3. The whole of the available power of the steam used. 4. A more even distribution of the strains upon the working parts, and larger bearing surfaces for the axles. 5. The same freedom of running as with a single engine, with the same adhesion to the rails as a coupled engine. The 6ft. wheel type of London and North Western Railway compound was introduced in 1884. The outside cylinders are 14in. and the inside 30in. diameter, stroke 24in. Joy’s gear is used for all the valves; the valves to the outside cylinders are below, and the valve of the l.p. cylinder is above the cylinder. The boiler steam- pressure is 175lb. per square in., but it is reduced to 80lb. when entering the low-pressure cylinder. The weight of the engine in working order is 42 tons 10 cwt. Heating surface: Tubes, 1,242 sq. ft.; fire-box, 159.1 sq. ft.; total, 1,401.5 sq. ft. Grate area, 20.5 sq. ft.
  • 30. Fig. 95.—“TEUTONIC,” A L. & N.W.R. “COMPOUND” LOCOMOTIVE ON WEBB’S SYSTEM An engine built to this design—the “Marchioness of Stafford”— was exhibited at the London Inventions Exhibition of 1885, and gained the gold medal. In 1890 the first of the “Teutonic” (Fig. 95) class of 7ft. 1in. compounds was constructed at Crewe Works. The leading wheels of this type are 4ft. 1½in. diameter. Total weight in working order, 45 tons 10 cwt. In these engines Mr. Webb’s loose eccentric motion is used for the low-pressure inside cylinder, but Joy’s gear is retained for the h.p. outside cylinders.
  • 31. Fig. 96.—“QUEEN EMPRESS,” ONE OF WEBB’S COMPOUND LOCOMOTIVES, L. & N.W.R. Another type of compound is the “Greater Britain.” During 1897 the “Greater Britain” and other engines of the class were coloured red, white, and blue, and employed to haul the Royal train when travelling over the London and North Western Railway system. They were then nicknamed the “Diamond Jubilees.” The special feature of this class is the length of the boiler, which is divided into two portions by means of a central combustion chamber. The heating surface is: fire-box, 120.6 sq. ft.; combustion chamber, 39.1 sq. ft.; front set of tubes, 875 sq. ft.; back set of tubes, 506.2 sq. ft. total, 1540.9 sq. ft. The two pairs of driving wheels are located in front of the fire-box, and in addition there are a pair of leading and a pair of trailing wheels. An engine of this class—the “Queen Empress” (Fig. 96)—was exhibited at the World’s Fair held at Chicago in 1893. Her leading dimensions are: Two high-pressure cylinders, 15in. diameter by 24in. stroke; one low-pressure cylinder, 30in. diameter by 24in. stroke; wheels—driving, 7ft. 1in. diameter (four in number); leading, 4ft. 1½in. diameter; trailing, 4ft. 1½in. diameter. Weight on each pair of driving wheels, 16 tons. Total weight of engine in working order, 52 tons 15 cwt. Total wheel base, 23ft. 8in. Centre to centre of driving wheels, 8ft. 3in. The most recent type of compound goods locomotives constructed by Mr. Webb has eight-coupled wheels, three pairs of
  • 32. which are located under the fire-box, the trailing pair being close to the back of the fire-box. The outside cylinders are below the top of the frame-plate, and incline towards the rear. This type of engine was designed by Mr. F. W. Webb, chief mechanical engineer of the London and North Western Railway, principally for working the heavy mineral traffic over that Company’s South Wales district, the first engine being built in 1893. The wheels (all coupled) are 4ft. 5½in. in diameter, with tyres 3in. thick. The distance between the centres of each pair is 5ft. 9in., the total wheel base being 17ft. 3in. All the cylinders drive on to one axle—the second from the front of the engine; the two high-pressure cylinders are connected to crank pins in the wheels set at right angles to each other, the low-pressure cylinder being connected to a centre crank-pin set at an angle of 135 degrees with the high-pressure cranks; the high-pressure cylinders are 15in. diameter by 24in. stroke, and the low-pressure cylinders are 30in. diameter by 24in. stroke. All the cylinders are bolted together and in line, the low-pressure being placed immediately under the smoke-box, and the high-pressure cylinders on each side outside the frames, the steam chests being within the frames. The engine weighs, in working order, 53 tons 18 cwt. The empty weights are as follows:— Tons. Cwts. Leading wheels 12 10 Driving wheels 14 8 Intermediate wheels 12 14 Trailing wheels 9 15 Total (Empty) 47 47 The latest type of a passenger compound locomotive built by Mr Webb is the 7ft. four-wheels-coupled engine “Black Prince” (Fig. 97), which was built at the Crewe Works in July, 1897. The engine has two high-pressure and two low-pressure cylinders, all being in line, and driving on to one axle, the high and low pressure cranks being directly opposite each other.
  • 33. One of the features of this engine is the method adapted for working the valves, two sets of gear only being used for working the four valves. Joy’s valve motion is used for the low-pressure valves, the valve spindles being prolonged through the front of the steam chest, and on the end of the spindle a cross-head is fixed which engages with a lever of the first order, carried on a pivot firmly secured to the engine frame. The other end of this lever engages with a cross-head fixed on the end of the high pressure valve spindle, and by this means the requisite motion is given to the high pressure valve. The leading end of the engine is carried on a double radial truck, the centre of which is fitted with Mr. Webb’s radial axle-box and central controlling spring. This arrangement permits of 1in. side play, and gives greater freedom to the truck when passing round curves than is possible in the ordinary type of bogie with a rigid centre-pin. One important object aimed at in the construction of this engine has been to get all the bearing surfaces throughout as large as possible. Each of the four journals in the radial truck is 6¼in. diameter and 1Oin. long. The driving axle, in addition to the two ordinary bearings, which are each 7½in. diameter and 9in. long, has a central bearing between the two cranks, 7in. diameter and 5½in. long. In the trailing axle the journals are 7½in. diameter, by 13½in. long. This engine made its first trip on August 2nd, 1897, and since then has been principally engaged in working the “up” dining saloon express, which leaves Crewe at 5.20 p.m., running through to Willesden without a stop—a distance of 152½ miles—and returning the same night with the Scotch sleeping saloon express, which leaves Euston at 11.50 p.m., running through to Crewe without a stop, 158 miles.
  • 34. Fig. 97.—“BLACK PRINCE,” L. & N.W.R., A 4- COUPLED 4-CYLINDER, COMPOUND ENGINE, WITH DOUBLE RADIAL TRACK The total distance run by this engine up to June 30th, 1898, was 52,034 miles. The high-pressure cylinders are 15in. diameter by 24in. stroke, and the low-pressure cylinders are 20½in. diameter by 24in. stroke. The heating surface is: Tubes, 1,241.3 sq. ft.; fire-box, 159.1 sq. ft.; total 1,409.1 sq. ft. Grate area, 20.5 sq. ft. A concise survey of other compound locomotives will be of interest at this juncture. Mr. Wordsell, the then locomotive superintendent of the Great Eastern Railway, in 1882 built a compound engine, with two inside cylinders, the h.p. 18in. and the l.p. 26in. diameter; the stroke was 24in.; steam pressure, 160lb. per sq. in. The coupled wheels were 7ft. diameter. The engine was fitted with a leading bogie, the wheels of which were 3ft. 1in. diameter; with her tender she weighed 77 tons in working order; her number was 230. A similar engine, No. 702, with Joy’s valve gear, was built in 1885. Mr. Wordsell also built a two-cylinder, six-coupled goods engine for the Great Eastern Railway, on the compound principle. This was fitted with the ordinary link motion. Mr. Wordsell, upon his appointment as locomotive superintendent of the North Eastern Railway, introduced compound engines on that
  • 35. line. These were provided with two cylinders, both inside, with the valves on top. The h.p. cylinder is 18in. and the l.p. 26in. in diameter, the stroke being 24in. Mr. Worthington thus describes the North Eastern Railway standard compound goods engine:—“In outside appearance this engine is neat, simple, and substantial. It weighs 40 tons 7 cwt., and has six coupled 5ft. 1¼in. in diameter. “The cylinders are placed, as in the passenger compound engines, beneath the slide-valves and inside the frames. “The chief features of this goods engine to be observed are the starting and intercepting valves, which enable the engine-driver to start the engine by admitting sufficient high-pressure steam to the large cylinder without interfering with the small cylinder, in case the latter is not in a position to start the train alone. “The two valves are operated by steam controlled by one handle. If the engine does not start when the regulator is opened, which will occur when the high-pressure valve covers both steam ports, the driver pulls the additional small handle, which closes the passage from the receiver to the low-pressure cylinder, and also admits a small amount of steam to the low-pressure steam chest, so that the two cylinders together develop additional starting power. “After one or two strokes of the engine the exhaust steam from the high-pressure cylinder automatically forces the two valves back to their normal position, and the engine proceeds working compound.” The North Eastern Railway has other compound engines constructed on the Wordsell and Van Borries system, a 6ft. 8¼in. four-coupled, with a leading bogie of locomotive, being turned out in 1886. Engines of this type have a heating surface of 1,323.3 sq. ft., a grate area of 17.33 sq. ft., and a working pressure of 175lb. per sq. in. Another North Eastern Railway type of compound has 7ft. 6in. single driving wheels and a leading bogie. The h.p. cylinder is 20in.,
  • 36. and the l.p. 26in. diameter, compared with 18in. and 26in. in the four- coupled class, the stroke being the same in each design—viz., 24in. The first of the 7ft. 6in. compound class of locomotives was constructed at the Gateshead Works in 1890. The engines of this design appear capable of doing very heavy work with a low coal consumption, the average being 28lb. per mile, which, considering the heavy traffic and speed maintained, is low, being, in fact, 2lb. per mile below that of any other class of engine engaged on the same traffic. With a train of 18 coaches, weighing 310 tons (including 87 tons, the weight of the engine and tender), a speed of 86 miles an hour was attained on a level portion of the road, the horse-power indicated being 1,068. These engines have a commodious cab, and the tenders carrying 3,900 gallons of water, thus making it possible for the run of 125 miles, from Newcastle to Edinburgh, to be performed without a stop. There is also a class of six-coupled tank engines, with a trailing radial axle. The stroke is 24in., and the diameter of cylinders h.p. 18in., and l.p. 26in. Compound engines have also been tried on the Glasgow and South Western Railway and on the London and South Western Railway. The advantages of express locomotives being fitted with leading bogies were speedily recognised by most of the locomotive superintendents. Mr. S. W. Johnson, the Midland chief, introduced a design of such engines in 1876. The steam pressure of the early engines of this class was 140lb., but in later years this was increased to 160lb., whilst in the recent engines the pressure is still further augmented. The same progress is to be noticed in the diameter of the cylinders of the Midland engines, the diameter having increased from 17½in. in 1876 to 19½in. at the present time. The size of the coupled wheels has also increased from 6ft. 6in. to 7ft. 9in. The length of stroke has been the same in all engines of this design—viz., 26in.
  • 37. Fig. 98.—JOHNSON’S 7ft. 9in. “SINGLE” ENGINE, MIDLAND RAILWAY The new Midland single express engines are illustrated by Fig. 98. These locomotives have inside cylinders 19½in. diameter, with a stroke of 26in. The driving wheels are 7ft. 9in. in diameter. By standing on a railway station platform alongside one of these engines, one gets a good idea of their immense proportions, the abnormally high pitch of the boiler being especially noticeable. Mr. Stroudley, in his “Gladstone” class of engines for the London, Brighton and South Coast Railway, adopted an entirely opposite practice. His engines had the leading and driving wheels coupled, and a pair of smaller trailing wheels. The coupled wheels are 6ft. 6in. diameter, and the trailing 4ft. 6in. diameter. The cylinders are inside, and measure 18¼1in. diameter, the stroke being 26in. The reversing apparatus is actuated by means of compressed air, supplied by the Westinghouse brake pump; whilst part of the exhaust steam is projected against the flanges of the leading wheels, and upon condensation upon the flanges forms a lubricant to the flange surface, when pressing against the inner sides of the rails. Fig. 99 is from a photograph of “George A. Wallis,” an engine of the “Gladstone” class.
  • 38. Fig. 99.—“GEORGE A. WALLIS,” AN ENGINE OF THE “GLADSTONE” CLASS, L.B. & S.C.R. The “Tennant” (Fig. 100) class of express engines, on the North Eastern Railway, deserves mention, being the design of a general manager during the North Eastern locomotive interregnum of 1885. The engines have four-coupled wheels, 7ft. diameter, and a leading pair of small wheels, cylinders being 18in. diameter, and 24in. stroke. The cab is somewhat similar to the Stirling pattern on the Great Northern Railway. The North British Railway engine, No. 592, was exhibited at the Edinburgh Exhibition of 1886, and Mr. Holmes, her designer, was awarded the gold medal. The driving and trailing wheels are coupled, their diameter being 7ft. The fore part of the machine is supported on a four-wheeled bogie. The symmetrical appearance of this and other North British Railway locomotives is spoilt by having the safety valve located above the dome casing. The cylinders are 18in. diameter, and 26in. stroke. No. 602, another engine of this design, is notorious as being the first engine to cross the Forth Bridge, when formally opened by the Prince of Wales on March 4th, 1890, the Marchioness of Tweeddale driving the engine upon the occasion.
  • 39. Mr. Holmes, in 1890, introduced another very similar design of North British Railway engines, but with coupled wheels only 6ft. 6in. diameter. These are known as the “633” class, illustrated by Fig. 101. Turning to the Great Eastern Railway, we have to chronicle some types of locomotives designed by Mr. Holden. The express passenger engines have a pair of small leading wheels and four- coupled wheels of 7ft. diameter, with cylinders 18in. by 24in. The valves are below the cylinders, which, by the way, are both cast in one piece. Fig. 100.—“1463,” N.E.R., ONE OF THE “TENNANT” LOCOMOTIVES In connection with this design of locomotive, the triumph of skilled mechanism, combined with the application of scientific research, deserves record, seeing that a troublesome waste product has been turned into a valuable calorific agent. We refer to the introduction of liquid fuel for locomotive purposes, as carried out under Mr. Holden’s patent.
  • 40. Fig. 101.—HOLMES’S TYPE OF EXPRESS ENGINES FOR THE NORTH BRITISH RAILWAY Now, sanitary authorities have large powers, and they are very fond of abusing these powers, and pushing matters to extreme issues—although at times, as we know from personal experience, they sometimes exceed their statutory powers, and find themselves in a tight place from which they can only retreat by payment of compensation and heavy law costs. In connection with the pollution of streams the authorities have very wide powers, and when they found the waters of the never clear or limpid Channelsea and Lea were further polluted by some oily, iridescent matter, with a pungent odour, the sanitary inspectors were soon ferreting out the offenders. The waste products from the Great Eastern Railway oil-gasworks at Stratford were found to be responsible for the nuisance, and the service of a notice requiring immediate abatement of the same was the result of the discovery. Mr. Holden, remembering the good old proverb, “Necessity is the mother of invention,” soon commenced to experiment with the matter
  • 41. which the sanitary authorities refused to allow to be emptied into the already impure waterways under their jurisdiction. The result of a series of trials on, first a six-coupled tank engine, and then on a single express, was a four-coupled express engine on the G.E.R., No. 760, named “Petrolea.” This locomotive was constructed in 1886, and in general appearance is similar to the four-coupled express engine just described. The heating arrangements are, however, supplemented by the liquid fuel burning apparatus, which may be briefly described as follows: The oil fuel is carried on this engine in a rectangular tank of 500 gallons capacity, but in later examples occupies two cylindrical reservoirs, which contain 650 gallons, placed on the top of the tender water-tanks, one on each side. The liquid fuel is supplied to these reservoirs through man-holes at the foot-plate end. The feed-pipes from these tanks unite on the tender foot-plate at the centre, and from this junction the oil is conveyed by the flexible hose pipe to the engine, where the supply is again divided to feed the two burners situated on the fire-box front just under the footboard. Both the liquid in the tanks and the injected air are heated before use, the former by means of steam coils in the tanks, and the latter by coiled pipes in the smoke-box. The heated liquid fuel and air are injected into the fire-box, through two nozzles in the form of fine spray, steam being injected at the same moment through an outer ring of the same nozzles. The steam divides the mixture of air and liquid into such fine particles that it immediately ignites when in contact with the incandescent coal and chalk fire already provided in the fire-box. The fire-box is fitted with a brick arch deflector.
  • 42. Fig. 102.—7ft. SINGLE ENGINE, G.E.R., FITTED WITH HOLDEN’S LIQUID FUEL APPARATUS The whole of the apparatus is controlled by a four-way cock fitted on the fire-box case, near the position usually occupied by the regulator. The positions of the cock in question are: (1) steam to warm coils in liquid fuel tank; (2) steam to ring-blowers on injectors; (3) steam to centre jets of ejectors; and (4) steam to clear out the liquid fuel pipes and ejectors. The success of “Petrolea” was so apparent and unquestionable that Mr. Holden’s patent system of burning liquid fuel was immediately fitted to other Great Eastern Railway locomotives, with the result that at the present time a number are fitted with his patent apparatus. The following Great Eastern Railway locomotives have been fitted to burn liquid fuel:— 9 four-wheel coupled express engines. 6 single express engines. (Fig. 102) 1 six-wheel coupled goods engine. 1 six-wheel coupled tank, and 20 four-wheel coupled bogie tanks.
  • 43. and the 10 engines of the new class of “single” bogie expresses. (Fig. 103.) The application of the “Serve” corrugated tube has also been introduced on the Great Eastern Railway in connection with the liquid fuel. The goods engine and also two of the express passenger engines have the “Serve” tubes. The experiment of burning liquid fuel has been very successful, only 16lb. of oil having been consumed per mile run, against an average of 35lb. of coal per mile, with coal-fired engines. Some very handsome Bogie Single Express Locomotives have recently been built at the Stratford Works of the G.E.R. Company to the designs of Mr. James Holden. They have been specially constructed for running the fast Cromer traffic. The boiler has a telescopic barrel 11ft. long, in two plates, and is 4ft. 3in. diameter outside the smaller ring. It contains 227 tubes 1¾in. external diameter, and the height of its centre line above the rail level is 7ft. 9in. The fire-box is 7ft. long, and 4ft. ½ in. wide outside, and has a grate area of 21.37 sq. ft., and is fired with oil fuel. The total heating surface is 1,292.7 sq. ft., the tubes giving 1,178.5 sq. ft., and the fire- box 114.2 sq. ft. The working pressure is 160 lbs. per sq. in. The driving wheels are 7ft., the bogie wheels are 3ft. 9in., and the trailing wheels 4ft. diameter. The total wheel base is 22ft. 9in., the bogie wheels centres being 6ft. 6in. apart, from centre of bogie pin to centre of driving wheel is 10ft. 6in., and from centre of driving wheel to centre of trailing is 9ft. The total length of engine and tender, over buffers, is 53ft. 3in. The cylinders are 18in. diameter by 26in. stroke, the distance between centres being 24in. The slide-valves are arranged underneath, and are fitted with a small valve, which allows any water that may collect in the slide-valve to drain off.
  • 44. Fig. 103.—“No. 10,” THE LATEST TYPE OF G.E.R. EXPRESS ENGINE, FIRED WITH LIQUID FUEL Steam sanding apparatus is fitted at front and back of the driving wheels. Macallan’s variable blast pipe is used, the diameter of the pipe being 5¼in., and of the cap 4¾in. This variable pipe is being adopted on all the Company’s engines. The pipe has a hinged top, operated from the foot-plate. When the hinged top is on the pipe, the area is that of a suitable ordinary pipe, and when the top is moved off the area is about 30 per cent. larger. It is found that a large proportion of the work of the engines can be done with the larger exhaust outlet, the result being a reduced back pressure in the cylinders and also a reduced vacuum in the smoke-box, and less disturbance of the fire and consequent saving of fuel. The tender is capable of carrying 2,790 gallons of water, 715 gallons of oil fuel, and 1½ tons of coal. It is provided with a water scoop for replenishing the tank whilst running. The weights of the engine and tender in working order are: engine, 48½ tons; tender, 36 tons; total, 84½ tons. The oil-firing arrangements embody a number of ingenious details, among them the supply of hot air for combustion from a
  • 45. series of cast-iron heaters placed around the inside of the smoke- box, the air being drawn from the front through the heaters to the burners for the exhausting action of the steam-jets used for injecting the oil fuel. The latter is warmed before leaving the tender in a cylindrical heating chamber, through which the exhaust steam from the air-brake pump circulates. The regulation of the oil supply is effected by a neatly designed gear attached to the cover and hood of the ordinary fire-door, and finally the burners or injectors are so constructed that should one require cleaning, inspection, or renewal, the internal cones can all be removed from the casing by simply unscrewing one large nut. These engines have polished copper chimney tops, and are painted and lined in the standard G.E.R. style, and fitted with the Westinghouse automatic brake.
  • 46. CHAPTER XIV. Modern L.B. and S.C.R. locomotives—Four-coupled in front passenger tank—Six-coupled tank with radial trailing wheels—Goods engines—“Bessemer,” four-coupled bogie express—“Inspector”—Standard L.C. and D.R. passenger engines—Goods locomotives—Three classes of tanks—Cambrian locomotives, passenger, goods, and tank—S.E. engines—A “Prize Medal” locomotive—Stirling’s goods and tank engine— His latest type of express engines—Adams’ locomotives on the L. & S.W.R.—Mixed traffic engines—Passenger and six-coupled tanks—Drummond’s “Windcutter” smoke- box—His four-cylinder express engine—North British passenger locomotives—Engines for the West Highland Railway—Holme’s goods and tank engines—His latest express type of engine—Classification of N.B.R. locomotives—N.B.R. inspection or cab engine —L. and Y. locomotives—Aspinall’s water “pick-up” apparatus—Severe gradients on the L. and Y. system—7ft. 3in. coupled expresses—“A” class of goods engines— Standard tank engines—L. and Y. oil-burning tank locomotives—Caledonian Railway engines—Drummond’s famous “Dunalastairs”—Excelled by his “Dunalastairs 2”—Six- coupled “condensing” tender engines—“Carbrooke” class—Dimensions of 44 types of Caledonian locomotives The modern engines on the London, Brighton, and South Coast Railway are designed by Mr. Billinton, and comprise— The four-coupled in front tank with a trailing bogie, of which “Havant,” No. 363, is an example. This engine was built at Brighton Works, 1897. Inside cylinders, 18in. by 26in.; diameter of coupled wheels, 5ft. 6in. diameter. Heating surface, 1,189 sq. ft. Steam pressure, 160lb. Weight in working order, 47 tons. “Watersfield,” No. 457, built at Brighton in 1895, is a specimen of the six-coupled goods tank engines, with radial trailing wheels. This class have inside cylinders, 18in. by 26in.; heating surface, 1,200 sq. ft.; diameter of wheels, 4ft. 6in.; steam pressure 160lb.; weight in working order, 51 tons. No. 449 represents the six-coupled goods tender engines, built by Vulcan Foundry Co. in 1894, from Mr. Billinton’s designs. Inside cylinders, 18in. by 26in.; wheels, 5ft. diameter; heating surface, 1,212 sq. ft.; steam pressure, 160lb.; weight in working order: engine, 38 tons; tender, 25 tons. “Bessemer,” No. 213, is one of the new type of four-coupled express passenger engines, with leading bogie, and was built at Brighton Works, 1897. Inside cylinders, 18in. by 26in.; diameter of coupled wheels, 6ft. 9in.; heating surface, 1,342 sq. ft.; working pressure, 170lb.; weight in working order: engine, 44 tons 14 cwt.; tender, 25 tons. Fig. 104 is from a photograph of “Goldsmith,” an engine of this class. Before closing this short description of the London, Brighton, and South Coast Railway locomotives, attention must be called to the combined engine and carriage named “Inspector,” No. 481 (Fig. 105). This engine was constructed in 1869 by
  • 47. Welcome to our website – the ideal destination for book lovers and knowledge seekers. With a mission to inspire endlessly, we offer a vast collection of books, ranging from classic literary works to specialized publications, self-development books, and children's literature. Each book is a new journey of discovery, expanding knowledge and enriching the soul of the reade Our website is not just a platform for buying books, but a bridge connecting readers to the timeless values of culture and wisdom. With an elegant, user-friendly interface and an intelligent search system, we are committed to providing a quick and convenient shopping experience. Additionally, our special promotions and home delivery services ensure that you save time and fully enjoy the joy of reading. Let us accompany you on the journey of exploring knowledge and personal growth! ebookfinal.com