So we now know how to make a simple web server, what can
we do with it?
Several possibilities come to mind:
- Custom server: if you don't want to install a full
function server for your PC, you can develop your own small,
customized server.
- Client Input: the server could record input from
the client, e.g. an experiment with distributed stations,
each sending their data to a central server.
- Data Monitoring: your custom server could download
recent data files being written by an experiment.
- Applet interaction: you can setup a two way link
between your client side applet and your server to carry
out special tasks (Chapter
15 discusses such a data monitoring system).
- Initiate External processes: a server could start
up an external process (see Chapter
23: Runtime class) via command to do some task such
as to making a measurement, running a calibration, etc.
- 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 C/C++, the Java
code is quite compact and straight-forward because of the
networking and threading capabilities in the core language.
Here again, the portability of Java to different platforms
also greatly increases the flexibility and range of applications
for your specialized servers.
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.
If your server application involves handling very high numbers
of connections, then you should look at section Chapter
9: Supplements: NIO Overview, which gives a brief overview
of the NIO packages that were introduced with Java 1.4. NIO provides
a range of tools to improve the performance of Java communications.
In particular, it includes classes that help deal efficiently
with high numbers of simultaneous connections by allowing for
non-blocking socket communications and the use of thread pools.
Latest update: August 18, 2005