Java Reference
In-Depth Information
Data monitoring -your custom server could provide recent data files written by an on-
going experiment or sensor reading. (See Chapter 15 for an example of a data-monitoring
system.)
Embedded server -inChapter 24 we discus how a server can run on a Java processor
in an embedded application such as monitoring a sensor or other instruments.
Applet interaction -you can set up a two-way link between your client-side applet and
your server to carry out special tasks.
Run external programs -aserver could start an external program to do some task
such as making a measurement or running diagnostic tests. In Chapter 23 we discuss
the Runtime class that provides a means to run external programs.
Secure interaction -you can customize your server to respond only to clients with
allowed usernames and passwords.
While one can certainly do such things with other programming languages, the
Java code is quite compact and straightforward because of the core networking
and threading capabilities. Furthermore, the portability of Java means that you
can run the server and client programs on a wide range of platforms with little or
no modification needed.
Note that the client and server roles are not absolute. A server can switch roles
and become a client when necessary. For example, a server at a remote station
could monitor some system and provide information to clients seeking status
reports on the system. However, the server might periodically contact a central
server to download data and status information, thus acting as client to the central
server.
14.8 Servers, servlets and JSP
We briefly mention here a couple of other popular Java web server tools: servlets
and Java Server Pages (JSP). We have seen how applets are Java programs that
run inside the browser on the client's machine. Servlets provide an analogous
approach on the server side in that they are Java programs run by a web server
to provide specialized services. They can do many of the same tasks that CGI
(Common Gateway Interface) programs perform such as processing input from
web page forms. However, they offer several advantages over CGI:
CGI programs run once and go away. Servlets can remain active and respond to another
request without additional startup costs.
Servlets are run in a Java thread by the server and are generally much faster to start up
than CGI programs, which require an operating system process.
A CGI program receives one input request, sends a response, and then dies. Servlets
can carry on a two-way conversation for an indefinite period.
A servlet can communicate with multiple clients simultaneously. An example is serving
the players in a multi-player game.
Search WWH ::




Custom Search