Home : Course Map : Chapter 15 :
Client/Server with a Physics Simulation
Course Map
Chapter 15

Processing Steps
Data Server
Run Data Server
    Demo 1
Data Client
DataClient Applet
    Demo 2
Client/Server Sim
    Demo 3
Run SimClient
    Demo 4

     About JavaTech
     Codes List
     Topic Index
     Course Guide
     What's New

For another example of a client/server for a technical application, we will create a socket based system that sends data from a physics simulation server to clients rather than just dummy random value data. We will use classes from our gravitational acceleration experiment simulation, discussed in Chapter 9: Physics, to build out simulator.

Such a system could be useful where you want to provide a central location for a simulation. This could be useful in a situation where the simulation is especially large and needs resources available on a particularly powerful machine or is being frequently modified and updated. Clients could log into the server, which would spin off a simulator dedicated to that particular client. If the simulation server existed on a multiprocessor system, then each simulator might get its own processor.

The Client/Server Procedure

The figures below illustrate the basic procedure and components involved in the system:

Diagram 1: Steps in the Simulation Client/Server system. (1) The SimServer waits for clients via its server socket. When a client contacts the server, a socket for that client is allocated. (2) The socket is passed to an instance of SimWorker, whose job is to tend to the needs of the client and also to open a SimApplet, which does the actual simulation. Note that the client also creates a SimClientWorker object to tend to the connection with the server. (3) The client passes to the simulation various parameters for the simulation such as the number of drop events to execute. The user can start a run via a button on the client interface. The SimApplet executes each drop and passes the data to the client via the SimWorker. Client analyzes the data from each event and also, when the run finishes, does its overall run analysis.


Diagram 2: Multiple clients can connect to the server and each will be assigned a simulator dedicated to it.

Another approach to the design of the system would combine the SimWorker with the simulation class (SimApplet) and combine the SimClientWorker with the SimClient class. This would reduce the communication lines that must occur among all of these actors.

However, separating them provides greater modularity and one could either use the worker classes, or subclasses of them, with other types of simulators and clients.

The Simulator

For our simulator we use classes developed for the gravitational acceleration experiment demonstration program in Chapter 9: Physics. Here we split the program and use the experiment simulation classes for the server side and the analysis code for the client side. The design follows the aim that the server produces the data and the client analyzes the data. The modularity provided by the object oriented design helps with adapting the classes here, though in some cases new classes had to be developed for this case.

More Info

The client/server simulation is described further on these pages:




Last update: Dec.11, 2004

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
22 23 24

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.