100% found this document useful (2 votes)
6 views

Learning Network Programming with Java 1st Edition Reese Richard M instant download

The document is a comprehensive guide on network programming using Java, authored by Richard M. Reese. It covers various topics including network addressing, client/server architecture, NIO support, UDP and multicasting, and network security. The book aims to help readers build efficient network-enabled applications while providing practical examples and code implementations.

Uploaded by

mrxtbggwqi883
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
6 views

Learning Network Programming with Java 1st Edition Reese Richard M instant download

The document is a comprehensive guide on network programming using Java, authored by Richard M. Reese. It covers various topics including network addressing, client/server architecture, NIO support, UDP and multicasting, and network security. The book aims to help readers build efficient network-enabled applications while providing practical examples and code implementations.

Uploaded by

mrxtbggwqi883
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Learning Network Programming with Java 1st

Edition Reese Richard M download

https://textbookfull.com/product/learning-network-programming-
with-java-1st-edition-reese-richard-m/

Download full version ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Learning Java Functional Programming 1st Edition Reese


Richard M

https://textbookfull.com/product/learning-java-functional-
programming-1st-edition-reese-richard-m/

Natural Language Processing with Java Community


Experience Distilled 1st Edition Reese Richard M

https://textbookfull.com/product/natural-language-processing-
with-java-community-experience-distilled-1st-edition-reese-
richard-m/

EJB 3 1 Cookbook 1st Edition M Reese Richard

https://textbookfull.com/product/ejb-3-1-cookbook-1st-edition-m-
reese-richard/

Learning Java Beginning programming with java for


dummies First Edition John Bach

https://textbookfull.com/product/learning-java-beginning-
programming-with-java-for-dummies-first-edition-john-bach/
Java Network Programming Fourth Edition Harold Elliotte

https://textbookfull.com/product/java-network-programming-fourth-
edition-harold-elliotte/

Learning Java An Introduction to Real World Programming


with Java Marc Loy

https://textbookfull.com/product/learning-java-an-introduction-
to-real-world-programming-with-java-marc-loy/

Learning Java An Introduction to Real World Programming


with Java 5th Edition Marc Loy

https://textbookfull.com/product/learning-java-an-introduction-
to-real-world-programming-with-java-5th-edition-marc-loy/

Java for Data Science 1st Edition Reese

https://textbookfull.com/product/java-for-data-science-1st-
edition-reese/

Neural Network Programming with Java Create and unleash


the power of neural networks by implementing
professional Java code 1st Edition Souza

https://textbookfull.com/product/neural-network-programming-with-
java-create-and-unleash-the-power-of-neural-networks-by-
implementing-professional-java-code-1st-edition-souza/
© CHB Books
© CHB Books

Learning Network Programming


with Java

Harness the hidden power of Java to build


network-enabled applications with lower network
traffic and faster processes

Richard M Reese

BIRMINGHAM - MUMBAI
© CHB Books
Learning Network Programming with Java

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: December 2015

Production reference: 1141215

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-547-1

www.packtpub.com
© CHB Books

Credits

Author Project Coordinator


Richard M Reese Shipra Chawhan

Reviewer Proofreader
Daniel MÜHLBACHLER Safis Editing

Commissioning Editor Indexer


Veena Pagare Monica Ajmera Mehta

Acquisition Editors Production Coordinator


Vivek Anantharaman Nilesh Mohite
Rahul Nair
Cover Work
Content Development Editor Nilesh Mohite
Arshiya Ayaz Umer

Technical Editor
Humera Shaikh

Copy Editor
Priyanka Ravi
© CHB Books

About the Author

Richard M Reese has worked in both industry and academia. For 17 years, he
worked in the telephone and aerospace industries, serving in several capacities,
including research and development, software development, supervision, and
training. He currently teaches at Tarleton State University, where he has the
opportunity to apply his years of industry experience to enhance his teaching.

Richard has written several Java books and a C Pointer book. He uses a concise and
easy-to-follow approach to topics at hand. His Java books have addressed EJB 3.1,
updates to Java 7 and 8, certification, functional programming, jMonkeyEngine, and
natural language processing.

I would like to thank my daughter, Jennifer, for her numerous


reviews and contributions; my wife, Karla, for her continued support;
and to the staff of Packt for their work in making this a better book.
© CHB Books

About the Reviewer

Daniel MÜHLBACHLER got interested in computer science shortly after


entering high school, where he later developed web applications as part of a
scholarship system for outstanding pupils.

He has a profound knowledge of web development (PHP, HTML, CSS/LESS, and


AngularJS), and has worked with a variety of other programming languages and
systems, such as Java/Groovy, Grails, Objective-C and Swift, Matlab, C (with Cilk),
Node.js, and Linux servers.

Furthermore, he works with some database management systems based on SQL, and
also some NoSQL systems, such as MongoDB, and SOLR. This is also reflected in
several projects that he is currently involved in at Catalysts GmbH.

After studying abroad as an exchange student in the United Kingdom, he completed


his bachelor's degree at Johannes Kepler University in Linz, Austria, with a thesis
on aerosol satellite data processing for mobile visualization. This is where he also
became familiar with processing large amounts of data.

Daniel enjoys solving challenging problems and is always keen on working with new
technologies, especially related to the fields of big data, functional programming,
optimization, and NoSQL databases.

More detailed information about his experience, as well as his contact details, can be
found at www.muehlbachler.org and www.linkedin.com/in/danielmuehlbachler.
© CHB Books

www.PacktPub.com

Support files, eBooks, discount offers, and more


For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.
com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign
up for a range of free newsletters and receive exclusive discounts and offers on Packt
books and eBooks.
TM

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser

Free access for Packt account holders


If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view 9 entirely free books. Simply use your login credentials for
immediate access.
© CHB Books

Table of Contents
Preface vii
Chapter 1: Getting Started with Network Programming 1
Network addressing using the InetAddress class 3
NIO support 5
Using the URLConnection class 5
Using the URLConnection class with buffers and channels 6
The client/server architecture 7
Creating a simple echo server 8
Creating a simple echo client 10
Using Java 8 to support the echo server and client 12
UDP and multicasting 14
Creating a multicast server 14
Creating the multicast client 15
Scalability 17
Creating a threaded server 17
Using the threaded server 19
Security 21
Creating a SSL server 21
Creating an SSL client 22
Generating secure keys 23
Summary 25
Chapter 2: Network Addressing 27
Networking basics 27
Understanding network basics 29
Network architectures and protocols 30
Using the NetworkInterface class 32
Getting a MAC address 35
Getting a specific MAC address 35

[i]
© CHB Books
Table of Contents

Getting multiple MAC addresses 36


Network addressing concepts 37
URL/URI/URN 37
Using the URI class 39
Creating URI instances 39
Splitting apart a URI 40
Using the URL class 41
Creating URL instances 42
Splitting apart a URL 42
IP addresses and the InetAddress class 45
Obtaining information about an address 45
Address scoping issues 47
Testing reachability 48
Introducing the Inet4Address 49
Private addresses in IPv4 50
IPv4 address types 50
The Inet4Address class 51
Special IPv4 addresses 51
Introducing the Inet6Address class 52
Private addresses in IPv6 52
The Inet6Address class 53
Special IPv6 addresses 53
Testing for the IP address type 53
Using IPv4-compatible IPv6 addresses 54
Controlling network properties 56
Summary 56
Chapter 3: NIO Support for Networking 57
Java NIO 57
Introduction to buffers 59
Using channels with a time server 60
Creating a time server 61
Creating a time client 62
The chat server/client applications 63
The chat server 64
The chat client 66
Server/client interaction 67
The HelperMethods class 68
Handling variable length messages 69
Running the chat server/client application 71
Handling multiple clients 72
The parts server 72
The parts client handler 74
The parts client 75

[ ii ]
© CHB Books
Running the parts client/server
Table of Contents

76
Asynchronous socket channels 78
Creating the asynchronous server socket channel server 79
Creating the asynchronous socket channel client 81
Other buffer operations 83
Bulk data transfer 83
Using a view 85
Using read-only buffers 86
Controlling socket options 86
Summary 87
Chapter 4: Client/Server Development 89
The HTTP protocol structure 89
The nature of HTTP messages 91
Initial request line format 92
Header lines 94
Message body 94
Client/Server interaction example 95
Java socket support for HTTP client/server applications 95
Building a simple HTTP server 96
Building a simple HTTP client 100
Client/server development using standard Java classes 102
Using the HttpURLConnection class 102
URL encoding 105
Using the HTTPServer class 106
Implementing a simple HTTPServer class 108
Managing response headers 112
Open source Java HTTP servers 113
Server configuration 115
Handling cookies 116
Summary 117
Chapter 5: Peer-to-Peer Networks 119
P2P functions/characteristics 120
Applications-based P2P networks 122
Java support for P2P applications 123
Distributed hash tables 123
DHT components 124
DHT implementations 126
Using JDHT 126
Using FreePastry 128
The FreePastry demonstration 129
Understanding the FreePastryExample class 129

[ iii ]
© CHB Books
Table of Contents

Understanding the FreePastryApplication class 131


Sending a message to a specific node 135
Summary 137
Chapter 6: UDP and Multicasting 139
Java support for UDP 140
TCP versus UDP 142
UDP client/server 142
The UDP server application 143
The UDP client application 145
The UDP client/server in action 146
Channel support for UDP 148
The UDP echo server application 148
The UDP echo client application 150
The UDP echo client/server in action 152
UDP multicasting 153
The UDP multicast server 153
The UDP multicast client 154
The UDP multicast client/server in action 156
UDP multicasting with channels 156
The UDP channel multicast server 159
The UDP channel multicast client 160
The UDP channel multicast client/server in action 162
UDP streaming 162
The UDP audio server implementation 163
The UDP audio client implementation 165
Summary 168
Chapter 7: Network Scalability 169
Multithreaded server overview 170
The thread-per-request approach 172
The thread-per-request server 173
The thread-per-request client 175
The thread-per-request applications in action 175
Thread-per-connection approach 178
The thread-per-connection server 178
The thread-per-connection client 179
The thread-per-connection applications in action 179
Thread pools 180
The ThreadPoolExecutor class characteristics 181
Simple thread pool server 182
Simple thread pool client 184

[ iv ]
© CHB Books
The thread pool client/server in action
Table of Contents

185
Thread pool with Callable 186
Using a Callable 186
Using a Future 188
Using the HttpServer executor 189
Using a selector 190
Creating the selector 191
Registering a channel 191
Using the selector to support a time client/server 193
The channel time server 193
The date and time client application 197
The date and time server/client in action 197
Handling network timeouts 199
Summary 199
Chapter 8: Network Security 201
Security 201
Secure communication terminology 202
Encryption basics 203
Symmetric encryption techniques 204
Generating a key 204
Encrypting text using a symmetric key 205
Decrypting text 206
Asymmetric encryption techniques 206
Generating and saving asymmetric keys 208
Encrypting/decrypting text using an asymmetric key 209
Saving asymmetric keys to a file 210
Creating a keystore 213
Creating and maintaining a keystore with keytool 213
Keytool command-line arguments 216
Creating and maintaining a keystore with Java 219
Symmetric encryption client/server 221
Symmetric server application 222
Symmetric client application 224
Symmetric client/server in action 226
Asymmetric encryption client/server 227
Asymmetric server application 227
Asymmetric client application 228
Asymmetric client/server in action 230
TLS/SSL 230
SSL server 231
SSL client 233
SSL client/server in action 234

[v]
© CHB Books
Table of Contents

Secure hash functions 235


Summary 237
Chapter 9: Network Interoperability 239
Byte order in Java 240
Interfacing with other languages 242
Interfacing with JVM based languages 242
Interfacing with non-JVM languages 243
Communication through simple sockets 244
The Java server 244
The C# client 245
The client/server in action 247
Interoperability through middleware 248
Creating a RESTful service 249
Testing the RESTful service 253
Creating a RESTful client 256
Summary 260
Index 261

[ vi ]
© CHB Books

Preface
The world is becoming interconnected on an unprecedented scale with more services
being provided on the Internet. Applications ranging from business transactions
to embedded applications, such as those found in refrigerators, are connecting to
the Internet. With isolated applications no longer being the norm, it is becoming
increasingly important for applications to be network enabled.

The goal of this book is to provide the reader with the necessary skills to develop
Java applications that connect and work with other applications and services across
a network. You will be introduced to a wide range of networking options that
are available using Java, which will enable you to develop applications using the
appropriate technology for the task at hand.

What this book covers


Chapter 1, Getting Started with Network Programming, introduces the essential network
terminology and concepts. The networking support that Java provides is illustrated
with brief examples. A simple client/server application is presented along with a
threaded version of the server.

Chapter 2, Network Addressing, explains how nodes on a network use addresses. How
Java represents these addresses is introduced along with support for IPv4 and IPv6.
This chapter also covers how Java can configure various network properties.

Chapter 3, NIO Support for Networking, explains how the NIO package provides
support for communication using buffers and channels. These techniques are
illustrated with a client/server application. The support that NIO provides for
asynchronous communication is also demonstrated.

[ vii ]
© CHB Books
Preface

Chapter 4, Client/Server Development, covers how HTTP is an important and


widely-used protocol. Java provides support for this protocol in a variety of ways.
These techniques are illustrated along with a demonstration of how cookies are
handled in Java.

Chapter 5, Peer-to-Peer Networks, discusses how peer-to-peer networks provide a flexible


alternative to the traditional client/server architecture. The basic peer-to-peer concepts
are introduced along with demonstrations of how Java supports this architecture.
FreePastry is used to illustrate one open source peer-to-peer solution framework.

Chapter 6, UDP and Multicasting, explains how UDP is an alternative to TCP. It


provides a less reliable but more efficient way for applications to communicate
across the Internet. Java's extensive support for this protocol is demonstrated,
including NIO support, and how UDP can support streaming media.

Chapter 7, Network Scalability, explains how, as more demands are placed on a server,
systems need to scale to address these demands. Several threading techniques
supporting this need are demonstrated, including thread pools, futures, and the
NIO's selector.

Chapter 8, Network Security, discusses how applications need to protect against a


variety of threats. This is supported in Java using encryption and secure hashing
techniques. Symmetric and asymmetric encryption techniques are illustrated. In
addition, the use of TLS/SSL is demonstrated.

Chapter 9, Network Interoperability, covers how Java applications may need to


exchange information with other applications that are written in different languages.
The issues that impact an application's interoperability are examined, including byte
order. Communication between different implementations is demonstrated using
sockets and middleware.

What you need for this book


Java SDK 1.8 is needed for the network programming examples that are encountered
in the book. An IDE, such as NetBeans or Eclipse, is recommended. NetBeans IDE
8.0.2 EE edition is used to illustrate the development of a web service.

[ viii ]
© CHB Books Preface

Who this book is for


This book is for developers who are already proficient in Java and want to learn
how to develop network-enabled Java applications. Familiarity with basic Java and
object-oriented programming concepts is all that is needed. You will learn the basics
of network programming and how to use a multitude of different sockets to create
secure and scalable applications.

Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.

Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"The SSLSocketFactory class' getDefault returns an SSLSocketFactory instance
whose createSocket creates a socket that is connected to the secure echo server."

A block of code is set as follows:


public class ThreadedEchoServer implements Runnable {
private static Socket clientSocket;

public ThreadedEchoServer(Socket clientSocket) {


this.clientSocket = clientSocket;
}
...
}

Any command-line input or output is written as follows:


Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]: First Last
What is the name of your organizational unit?
[Unknown]: packt
What is the name of your organization?
[Unknown]: publishing
What is the name of your City or Locality?
[Unknown]: home

[ ix ]
Another Random Scribd Document
with Unrelated Content
“The Chemical Sense”
In the simpler multicellular organisms, which develop by cell
division and multiplication from a single cell, the cells differ from the
original type and from each other in position, structure, and
function. In the course of growth the organism originally spherical in
shape becomes modified by irregular growth of cells, producing folds
and prominences. Cells are crowded out of shape; some lie at the
base of a depression protected from stimulation; others occupy
positions which make them especially liable to be acted upon by
such stimuli. In the course of these modifications some of the cells
become especially adapted for receiving impressions, others for
conducting or transmitting these impressions to various parts of the
organism, others for producing movements of the organism. It is
with the first type of cell that we are concerned, the receptor
mechanisms. They are in the simpler organisms, adapted to receive
two sorts of stimulation, mechanical and chemical. In fact, through
the whole series of multicellular organisms such reactions to
mechanical and chemical stimuli have been noted more or less
definitely, although special sense organ structures have in many
cases not been discovered. This is especially true for the reactions to
chemical substances. It is customary to speak of the “chemical
sense,” to signify these responses to chemical substances, without
any attempt to differentiate between smell and taste. Obviously, in
the case of organisms which live in a fluid environment, this
chemical sense might be called taste, since it would correspond in a
way to that sense in man, for which the adequate stimulus is a fluid.
But since it is a “distance receptor,” in that objects at a distance can
produce responses, probably by diffusion of substances in the fluid,
it might also be looked upon as more nearly resembling the smell
sense. In most cases structure offers no help in settling the matter.
In the medusa, or jellyfish, one of the earliest forms in which a
nervous system and sense organs are found, the tentacles are
especially sensitive to chemical stimuli, much less so to mechanical
stimuli. To the former they respond by shortening and twisting
themselves about the object. As for sense organs in these parts,
there are small club-shaped papillæ in the neighborhood of the
tentacles, differing somewhat in character in the different species.
These papillæ contain a narrow canal lined with thick cylindrical
cells. As far as both structure and function are concerned, they may
be considered either as taste or smell organs.
In the flat worms, where a nervous system with a rudimentary
brain is found, the reaction to chemical stimulation is not clear. This
organism has specialized responses, among which is a movement
toward food placed near it. But whether this is a reaction to chemical
stimuli alone or combined with mechanical is not known. No taste
organs have been found. Pits or depressions found on the lateral
surface of the anterior end of the worm, and supplied with nerves
from the brain, have been regarded as olfactory rather than as taste
organs.
In the annelid group, of which the earthworm may be taken as an
example, there are well-defined chemical reactions, which more
nearly resemble taste reactions than the cases previously
mentioned. Here a positive reaction to food substances seems to
occur only when these substances come into contact with the body.
For instance, the characteristic burrowing reactions of the
earthworm are not aroused by placing filter paper soaked in manure
near them, but only when the paper is actually in contact with the
body. Negative reactions, however, to strong chemical stimulation
may take place without contact. Attempts have been made by Parker
and Metcalf to show specialized taste reactions to different chemical
substances by measuring the latent time in the responses to various
substances brought into contact with the body. From such evidence
as this it would appear that earthworms have specialized reactions
to the chlorides of sodium, potassium, lithium, and ammonium,
which are indistinguishable to the human taste sense, with their
common salt taste. These results are interpreted as indicating
qualitatively different effects of the stimuli. In these organisms it has
been possible to discover taste organs, distinct from the olfactory
organs. They are described as cup-shaped organs, which may be
either depressions or prominences. They occur in large numbers and
are widely scattered over the body. They are said, however, to be
especially numerous at the edges of the mouth and within the
mouth cavity.
The crustacea, among which are the crabs and the lobsters,
characterized by their hard shell-like covering, show certain specific
reactions to chemical substances when these come into contact with
the parts of the body near the mouth. Reactions to chemical stimuli
applied to any part of the body of the crayfish have been reported
by Bell. The positive reactions were such as to bring the substance
toward the mouth and the negative reactions such as to remove the
substance. Responses to such substances at a distance are
uncertain. But it is difficult to differentiate between possible smell
and taste reactions. The sense organs in these organisms are usually
located upon the antennæ, or feelers, in the neighborhood of the
mouth. Here there is a different kind of response to chemical and
mechanical stimulation. No structures with a specific taste function
have been described, although smell and tactile organs have been
localized.
In the organisms described above, the chemical, or, more
specifically, the taste, sense is a food sense,—edible and inedible
substances causing reactions of different character. The reactions to
stimuli within the edible group, however, show no variation. In the
insects, especially the ants, bees, wasps, etc., there seem to be
qualitative differences in the effect produced by chemical
substances. It is by means of this chemical sense that bees and ants
are able to find food at a distance, to return to their homes under all
sorts of adverse conditions, and to distinguish nest mates from
enemy intruders. But, since these are all reactions to stimuli at a
distance, they must be attributed to the smell sense, rather than to
the taste sense. But in the case of these organisms a sharp
distinction between smell and taste seems possible. Forel and others
have offered honey mixed with strychnine to ants, who seized it
greedily, indicating an olfactory sensibility. But immediately after the
honey had touched the mouth parts, avoiding reactions, such as to
remove the substance, followed, indicating sensitiveness to the bitter
substance. Wasps and bees will make the same sort of responses if
distasteful substances which are inodorous are mixed with pleasant,
odorous substances. The sensitivity to tastes varies considerably in
different insects, being very great in bees and ants. From such
experiments as the above it has been concluded that the smell
organs are located on the antennæ and that the taste organs are
located on the lips and in the mouth. Microscopical examination
shows that in all insects the tongue and inside of the mouth are
covered with minute pits, or depressions. In each pit there is a
minute hair, or rod. Some observers say that this rod is hollow and
perforated at the end, thus communicating with the nerve which
ends at its base. Other observers say that there is no perforation
upon the end of the hair. However this may be, there seems to be
no doubt that these are the taste organs. The same type of structure
has been reported on the proboscis of the bumblebee, the hive bee,
and the common fly. They are said to resemble a hollow hair, the
channel communicating with a nerve fiber at its base. In the insects,
then, we find the earliest definitely specialized taste mechanism.
Chemical Sense in Fishes
In the fishes, again, the distinction between the senses of smell
and taste becomes more difficult, on account of their fluid
environment. But, disregarding the distinction between smell and
taste, the general chemical sense plays a very important part in the
life of the fish. Now, some observers have included all of this
sensitivity to chemical substances within the sense of smell, while
others have attributed a part of it to a taste mechanism. As
representative of the latter, Herrick’s conclusions are of interest: “In
fishes the gustatory system is much more extensively developed
than in mammals, especially the vagal part which supplies the taste
buds in the gill region. In some species of fishes, moreover, taste
buds appear in great numbers on the outer skin, and these are in all
cases innervated from the seventh cranial nerve. In the common
horned-pouts, or catfishes, and in the carps and suckers these
cutaneous taste buds are distributed over practically the entire body
surface, and especially on the barblets.... These sense organs and
their nerves are entirely independent of those of the lateral line
system, and of the ordinary tactual system, though the gustatory
and tactual systems have been shown experimentally to coöperate in
the selection of food.”
Herrick determined by experiment that the sense organs thus
generally distributed over the body of the catfish really had a taste
function. Food placed at a distance from the fish produces only
restless movements, indicating that the eyes do not direct them to it.
But if food comes into contact with the mouth parts, or, in fact, any
part of the body, it is immediately seized. To show that this reaction
is not alone due to tactual stimulation, the tactual organs were first
stimulated with cotton wool, which produced the characteristic
seizing reaction. But after stimulation was continued for a while
reaction no longer followed. If at this point the cotton wool be
soaked with meat juice, the seizing reaction is again set up.
Adaptation to tactual stimulation has taken place, leaving the taste
organs to function alone. To show further that the responses did not
depend on olfactory stimulation, the olfactory nerves of certain
fishes were cut. When the experiment was performed, after recovery
from the operation the responses were the same as in normal fish.
The experiments of Parker show further that the mouth and
external surface of the body of certain fishes are sensitive to sour,
salt, and alkaline solutions. Sheldon obtained about the same
results. The external skin covering is not sensitive to sugars. The
tongue of fishes presents a smooth, gray, dorsal surface, devoid of
elevations or papillæ, which characterize the tongues of many other
organisms. Nor is it a mobile organ in comparison with other
species. On the whole, the tongue itself seems little adapted for
arousing taste sensations.
The system of “lateral line” organs of fishes have at times been
thought to be concerned with the chemical sense. This is probably
not the case, although their exact function is a question still under
dispute.
In a general way, the taste buds, or sense organs of taste of
fishes, resemble those of the human being. They are either flask- or
cup-shaped, and are composed of two types of cells, called
supporting cells and taste cells. The latter cells end peripherally in a
hair or bristle, just as the same kind of cell in the human taste bud.
Land-Dwelling Animals
There seems to be no experimental evidence for a specific sense
of taste in amphibia, or reptiles. But sense organ structures have
been described upon the tongue and soft palate of the frog, where
they are said to occur in hundreds. They are disc-shaped structures,
made up of several kinds of cells, which correspond to the real taste
cells and supporting cells of the human sense organ. The taste cells
end peripherally in several hairs or bristles, and at their central end
make connection with nerve fibers. In the reptile group there is
neither experimental evidence of taste sensitivity nor anatomical
evidence of the presence of taste corpuscles on the tongue or in the
mouth cavity.
The experimental evidence for the taste sense in birds is slight. It
certainly is greatly overshadowed by the keen senses of sight and
hearing. Birds seem to represent one case, however, in which taste
is more important than smell. Taste sensitivity for different chemical
substances, in the case of young chickens, at least, seems clear from
certain studies of instinct and learning, in which they accept certain
kinds of food and reject others after tasting them. In considering the
sense of taste in birds it must be remembered that most of them
swallow their food without chewing it or without having it reduced to
liquid form through mixture with saliva. The tongue, which varies in
character considerably in different types of birds, is in most cases
covered with a horny coat. Numerous hard papillæ are found upon
its surface. Microscopical examination of these papillæ shows
nothing which can correspond to taste buds or to gustatory cells.
The parrot is said to form an exception to most birds, in that it has a
relatively soft and fleshy tongue, with numerous papillæ, and also in
that it chews its food.
In the duck, which has a large tongue, there are certain portions
which lack the hard covering common to birds’ tongues. Here, in
addition to a large number of tactile corpuscles, there are groups of
cells which resemble somewhat true taste corpuscles. The peripheral
ends of their cells reach the surface of the mucous covering of the
tongue. The cells do not end in the bristle, or hair-like, formation, as
those of the human taste cells, but in a pointed elongation of the
protoplasm. Experimental evidence of the function of these
structures is lacking.
Taste sensitivity and the structure of the taste organs differ greatly
in the mammals, but there seem to be two characteristics in
common, namely, the localization of the taste corpuscles within the
mouth and the importance of the tongue in arousing taste
sensations. The character of the mucous lining of the mouth also
shows great variation in the number of papillæ and the taste buds
which they contain. The number of papillæ varies from two or three
in the marsupials and four in the elephant to an extremely large
number in rodents, e.g., the rat. The papillæ are in general quite
similar to the three most common forms in the human taste organs,
the circumvallate, the fungiform, and the filiform, and have about
the same location in relation to each other. The greatest difference is
in the prominence of the fourth type, the foliate papillæ in certain
mammals, as compared with man. These are seen best in the rabbit,
as folds directed downward and forward on the sides of the tongue
in its posterior portion. They have been considered to result from the
great number of papillæ which throw the mucus into folds. Each
foliate papilla is composed of a number of parallel ridges, each ridge
in turn being composed of papillæ of the fungiform type. Between
the ridges there are narrow ditches. It is in the side walls of these
that the taste corpuscles are found in greatest numbers. Thus, these
ditches are analogous, in function at least, to those of the
circumvallate papillæ. Their origin, however, seems to be different
from that of the circumvallate. In the monkey one finds less
prominent folds on the sides of the tongue, rich in taste corpuscles,
which represent the foliate papillæ.
The taste corpuscles themselves have about the same
characteristics in all mammals as in man. There are differences in
size, to be sure, but their structure is the same, and the supporting
cells, gustatory cells, and nerve fibers are present in them all.
This survey of taste in the animal kingdom suggests the
conclusion that the taste organs represent a modification of the
original skin sensitivity or touch sense, and surely a slight
modification when compared with the senses of sight and hearing. A
certain resemblance has been remarked by Wundt and others
between the touch corpuscles and the gustatory corpuscles. His
interpretation is that the whole body was originally endowed with
the touch sense, while certain parts being affected continually by
specific sorts of stimuli, became adapted to them by undergoing
modifications of structure. The head or mouth end of the animal was
more subject to chemical stimulation, and the adaptation of the
tactile organs to this particular form of stimulation resulted in the
development of the senses of taste and smell. To consider taste as
one of the lower senses, in the sense of being least highly developed
and the earliest to appear, is justified from this survey of the
evolution of the taste sense, if from no other point of view.
CHAPTER XI

Gustatory Imagination and Memory


The Nature and Frequency of Mental Images
It is a familiar fact that in one way or another and in different
degrees to different individuals it is possible to have sensory
experiences without the actual presence of their accustomed stimuli.
Thus, many people can recall “in their mind’s eye” the colors of
objects, their shape and structure, when they are no longer in the
presence of the object thought of. Or, “in their mind’s ear,” they can
hear the blare of a trumpet, the voice of a friend, the hissing of
steam, when no corresponding stimulus is present to the ear.
Similarly, “in imagination” many can experience the tactual feel of
velvet, the odor of onions, the warmth of sunshine, the ache of a
tooth, the nausea of seasickness.
“Thus, I can call up in my mind’s eye, more or less vividly, my
boyhood home, and seem to see, though more obscurely than if I
were present on the spot, the house and barn, the grape arbor, the
garden, even my little bookcase in the library. I can smell the honey
in the bee boxes, and can hear the general hum and stir of the hive.
I can do this because I can call up images of these past experiences.
Or, by putting together the images of wheels, sails, birds, and ropes
which I have actually seen I can create in my mind’s eye an
aeroplane of a pattern which has never yet been constructed.” This
constructive performance would constitute “imagination” as
distinguished from mere “imagery.”
These images of imagination are not to be confused with the after
sensations which we have already described. They may be
experienced days, or even years, after the first application of the
original stimulus. Nevertheless, these “mental images,” or “centrally
excited sensations,” are described as essentially sensory in character
—they have the attributes of all sensory experiences, such as
intensity, extensity, duration, clearness, locality, quality, and
modality. In fact observers have been found for whom these mental
images were so realistically sensory that actual negative after
sensations, in the case of visual images, have been reported as
following upon them.
In the case of many individuals, these experiences of objects in
their absence are relatively rare and obscure, and in some cases,
indeed, are so obscure as to lead the individual to deny the
existence of such experiences. In still other cases the centrally
excited sensations, the mental images, are experienced in their vivid
and, apparently, immediately sensory form only under special
conditions, as in dreams, hallucinations, drowsiness, or fatigue, or
under the influence of special drugs. It has appeared from the study
of mental images that, in so far as they are present, they are not
equally reported in the different modes of sensation. Visual images
in some cases, auditory images in other cases, and motor images in
still others, have seemed to be so specially frequent, vivid, or easily
aroused that at one time it was customary to classify individuals on
the basis of their images as visuelles, audiles, motiles, and efforts
have even been made to adapt a method of teaching to the
presumed “imagery type” of the student. In the present connection
our interest is only in inquiring whether and in what degree “images
of taste” are present.
Mental Images of Taste
Is there a “gustatory” or taste imagination as well as a visual or an
auditory imagination? It should, of course, be borne in mind that
tastes may be “thought of,” “referred to,” or “indicated” without
there actually being taste qualities present in experience. Thus, I
may refer to the “saltiness of the pork” and discuss it in detail
without having in consciousness the sensory tang and quality of
“salt.” The saltiness may be “represented” in my thinking in this
case, not by a taste quality at all, but by the word which stands for
such a quality, or even by a visual picture of a white granular
substance, or an elongated strip of meat. Only if the immediate and
unanalyzable experience of sensory “salt” is present is there
evidence, in this case, of an “image of taste.”
Obviously, we must mainly rely in such cases on the testimony of
the observer, although there have been investigations made of a
more objective sort, in which it is shown that the reported “images”
are so similar in character to actual sense experiences that the
observer, under appropriate conditions, cannot distinguish between
the two.
If we turn to the results of introspection or individual testimony,
we find that if taste images exist at all they are at least reported as
very much less frequent and vivid than are images from other
senses. Thus, one observer, who in the course of two years’
observation of his own experience recorded 2,500 “images,”
classified these as follows:

Vision 57%
Hearing 20%
Smell 6%
Taste 6%
Touch 4%
Movement 3%
Temperature 2%
Organic 1%
Emotional 1%

Much the same state of affairs is revealed if one attempts, when


certain objects are named, to record the imagery which the name
evokes. In response to the word “tornado” some individuals at once
report visual appearances of falling houses and waving trees, while
others report auditory experiences of crashing buildings and rushing
wind. Within a few moments most observers report the appearance
of images from various senses, though some of them are more vivid,
more prompt, or more enduring than others. In the case of taste,
however, it is rare that images are reported as either vivid, prompt,
or lasting. Usually when such an image is reported at all it is
described as lagging behind the images of other modes, appearing
to be dragged in or reënforced by them, and to be transient, weak,
and fluctuating. It seems, also, that, although images of taste are
not easily aroused directly by words, their appearance is facilitated if
a visual image or impression is present with them. Consequently,
when the poet or the advertising writer desires to provoke imagined
tastes in his readers he often attempts to arouse them more
effectively by presenting suggestive pictures of scenes associated
with the object, or a tempting array of the articles themselves in an
agreeable setting.
Taste in Dreams and in Hallucinations
Reports of the sensory components of dream experiences show
taste to be an inconspicuous factor in dream life. The following table
shows the results obtained by two independent investigators when
dreams of various individuals were analyzed into the sensory
elements reported:
Percentage of
Occurrences
Sensory 381 300
Mode Dreams Dreams
Vision 84.5% 67%
Hearing 67.7% 26%
Touch 10.8% 8%
Smell 6.9% 1%
Taste 6.3% 1%
Records of the hallucinations of sane and insane people also show
taste to play a relatively minor rôle, so far, at least, as frequency of
report is concerned. In both cases visual, auditory, tactile, and
olfactory hallucinations seem to be more common experiences.
“Subjective tastes,” or tastes which do not appear to be caused by
the action of any substance in the mouth, are, however, by no
means unknown, although in most cases it is apparent that these
tastes come from some unsuspected irritation of the taste organs by
actual agents. Substances circulating in the blood may often be seen
to be responsible for these “subjective tastes.” Thus, in diabetes the
excess of sugar in the blood may give rise to a persistent sweet
taste, and in case of jaundice biliary products often produce
sensations of bitter. Various drugs, when present in the blood
stream, also provoke well-known effects in taste, and it is quite
probable that the taste hallucinations associated with nervous and
mental disorder have their origin in some abnormal irritation of the
nerves or brain centers involved in taste. Distilled water, which is
presumably as tasteless a substance as could be found, is reported
as tasteless by only about 50 per cent of observers. About 25 per
cent report it as having a bitter taste, while certain cases are found
in which it tastes sweet, or salt, or sour, or as having some unknown
taste. As the result of careful study of these facts, Brown suggests
that “we may perhaps infer that the ‘taste’ of water is not, after all,
a taste quality, but is due rather to the presence or absence of some
tactual characteristic; the absence, perhaps, of the ‘bite’ which is
associated with sweet, salt, and sour alike.” It is also possible that
mechanical stimulation of the taste organs can produce true taste
qualities, just as mechanical stimulation of the retina produces spots
of light and the tapping of a “warm spot” may produce a faint
sensation of warmth.
CHAPTER XII

Unusual and Abnormal Taste Experiences


Gustatory Hallucinations and Auræ

Disorders of taste are for the most part neither as varied nor as
bizarre as the abnormal conditions of the more complex senses.
Illusions of taste, hallucinations, and subjective tastes we have
already referred to as frequently found. But of them little can be
said, except that they occur, and that they present very little of
psychological interest. The appearance of these subjective tastes
may in some cases be due merely to the fact that “a taste sensation
easily associates itself with certain muscular sensations. Thus,
pressure on the base of the tongue provokes the movements of
vomiting. With this muscular sensation may be associated a
sensation of bitter, which accompanies violent nausea.” In ways
similar to this some observers would explain the reports of others
who find taste sensations to be produced by mechanical stimulation
of papillæ. Most observers do not get such results, and it may be
that these sensations when they are reported are of the associated
variety.
In the case of certain abnormal nervous conditions, however,
these features may assume rather striking proportions. Thus, in the
“auræ,” or preliminary symptoms preceding an epileptic attack, the
patient often experiences unpleasant bitter or metallic tastes, and
distressing feelings of numbness of tongue, etc. These sensory
manifestations are, however, by no means as elaborate as are the
“auræ” of some of the other senses, notably hearing and vision.
Partial and Complete Ageusia
Conditions of partial or complete ageusia, or loss of taste, are well
known. Such conditions may result from the local application of
various drugs to the end organs, the paralyzing effect of drugs on
the nerve trunks, injury to, or operations on, these nerves, or
damage through injury, disintegration, or removal of special brain
areas.
Taste Hallucinations of the Insane
In the case of the mentally deranged taste hallucinations are
usually disagreeable, and they are often rationalized into a fabric of
delusions,—foul gases are said to be blown upon them, poisons are
being placed in their food. Such patients behave in realistic manner,
making various defensive reactions, such as stuffing the nostrils with
paper or cloth, spitting, and refusing food. In some cases these
hallucinations of the insane obviously originate from local
inflammation in the peripheral tissues, or from glandular
disturbances, and, hence, do not in themselves constitute important
pathological symptoms. In some cases, however, such hallucinations
arise quite independently of such acute local conditions of irritation,
as in chronic psychic disorders or dementias. Under such
circumstances they have greater significance, as they point to more
deep-seated mental and nervous disturbance. Just as in normal life
taste and smell are very closely associated with each other, so, in
these cases of insane hallucinations, disorders of taste sensation are
likely to involve olfactory irregularities as well.
Synæsthesias of Taste
An interesting though apparently somewhat rare phenomenon in
the field of sensation is what is known as “synæsthesia.” By this is
meant cases in which a given sense quality arouses, or is intimately
associated with, qualities belonging to other sensory modes. Thus, in
the case of vision and hearing, some individuals perceive the
different vowel sounds, or the sound of musical instruments, as
having color. One such person reports that to him all the consonant
sounds seem to be very dark purple, while among the vowel sounds
“a” seems yellow, “e” is pale emerald, and “u” is light dove color.
Taste, far from being an exception in this case, is one of the
senses in connection with which “synæsthesias” must often occur.
Salt, for instance, is described by one observer as dull red, bitter as
brownish, sweet as clear bright red, and sour as green or greenish-
blue. To another observer the taste of meats seems red or brown,
the taste of Graham bread is rich red in color, while all ice creams
(except chocolate and coffee) taste blue. To still another reporter the
sound of the word “intelligence” tastes like fresh sliced tomatoes,
while the sound of the word “interest” tastes like stewed tomatoes.
There has been much speculation as to the probable meaning and
mechanism of these synæsthetic experiences. Investigation seems
to show that the particular combinations are by no means universal,
even among those who report such observations,—they seem to be
individual and personal in their nature and presumably in their
origin.
It seems quite probable that in the main these synæsthesias
represent uncritical confusion of sensory qualities with other sensory
qualities, or with the affective qualities, the feelings, which
accompany them. Thus, we often hear such phrases as “bright
taste,” “heavy taste,” “dark brown taste,” “green taste,” “soft taste,”
“hard taste,” “smooth taste,” etc. It is clear in most of these cases
that either a touch component is included in the total taste
experience (as in “smooth taste,” “soft taste,” “hard taste”), or that
kinæsthetic (muscular) factors are so included (as in “heavy taste”),
or that the phrase is more or less designedly an analogy, or other
figure of speech (as in “sharp taste,” “bright taste,” “clear taste”).
The basis of such analogies is sometimes rather easily discerned,
and often is seen to be the “feeling tone” which the sensation
arouses,—the effect or “affect” which it produces. Thus, a heavy
weight retards, inhibits, and overpowers us. Some tastes have this
same overpowering affective tone, and may be intelligibly described
as “heavy.” A clear, bright day gives us recognizable feelings of
pleasantness, relief, and gives to objects a distinctness of contour.
Some tastes, being well defined, definitely localized, and highly
agreeable and soothing, may, then, be intelligibly described as being
“clear,” “bright,” or “pointed.” These illustrations represent, to be
sure, only simple forms of such synæsthesias. But even the
resemblance of the sound of “intelligence” to the taste of fresh sliced
tomatoes is by no means incomprehensible when we reflect that
“freshness” means “alertness,” “sliced” suggests sharpness of edge,
while tomatoes thus prepared are usually mature and ripe. For are
not alertness, keenness, and maturity the very marks of intelligence,
just as “dullness” and “greenness,” also sense qualities, are
expressive of its absence? In somewhat the same way we commonly
speak of “sweet odors,” “sweet sounds of music,” or even sweet
visual experiences, as in “a sweet face.”
A few individual cases of taste synæsthesia have been studied in
some detail. Such individuals are often shown to have a defective
sense of taste and to rely largely, in their recognition of taste, on
touch accompaniments, affective characteristics, and such “color”
experiences as the various tastes are said to induce.
Perversions of Taste
Under certain unusual organic conditions, and also still more
commonly in the case of degenerate and neurotic individuals,
various perversions of taste occur. These perversions do not seem to
be exclusively gustatory in character, since they involve more general
factors, such as appetite, craving, and emotional disturbance. The
name parorexia is sometimes given to these perversions of taste and
appetite. One of the subforms, known as malacia, takes the form of
an urgent desire for hot spices, or for sour and acid foods, such as
pickles. What is known as “salt hunger” is a very similar condition,
especially often found among the lower animals. Another form of
such perversion, known as pica, shows itself in the desire to eat
such substances as clay, chalk, and similar gritty or earthy
substances. Especially often among children and among certain
primitive peoples the chewing of these substances often seems to
give a satisfaction quite unfamiliar to the majority of mankind. Little
is known about such perversions beyond the fact that they have
often been reported.
Under certain conditions of mental degeneracy and nervous
disorder perversions sometimes arise which have been classed under
the term allotriophagia. This perversion takes the form of eating with
apparent relish various kinds of filth which are commonly offensive
and disgusting. In these cases it is quite possible that there is no
genuine taste disorder. Many, if, indeed, not most, of our revulsions
against substances known as filth arise on the basis of associated
circumstances, rather than on the simple basis of their taste
qualities. The falling away, or deterioration, of these associative and
æsthetic controls in the case of the demented and degenerate, and
their absence in the case of the feeble-minded and imbecile, may
easily lead to reactions which suggest but do not necessarily involve
genuine taste disorder.
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!

textbookfull.com

You might also like