Lecture 15A
DataMonitorDesign
Processing Steps
Run DataMonitor
DataClientApplet
DataServer
DataSender
DataClient
DataReader

Lectures

1A: Introduction
1B: Java Intro
2A: BuildingBlocks
2B: Objects
3A: More Objects
3B: Exceptions
       & Threads
4A: Waves
4B: Nuclear &
       Particle
5A: AWT
5B: More AWT
      & Graphics
6A:Detectors &
      Simulation
6B: LHC/Atlas &
     RandomSims    
7A: Swing
7B: Java2D
8A: Java Apps
8B: Dialogs &
    MoreClasses
9A: Java I/O
9B: Utilities,
        Unicode
10A: More
    Threading
10B: File
    Handling
11A: Array,Print,
    Images
11B: SimplePhysics
    Simulation
12A: Tips &
    Techniques
12B: More Tips &
    Techniques
13A: Satellite
    
Simulations
13B: Intro to Java
    Networking
14A: Java Servers
14B: HTTP Server
15A: ServerClient
15B: ServerClient
   Expt.Simulation
16A: Course
          Review
16B: ExerciseTest
        Discussion

    Contacts
    Description
    Exercises
    Index
    Outline
    Q&A
    Resources
    StudentInfoForm
    Student Pages
    What's New

 

Home : Lectures : Lecture 15A : DataReader
DataReader

DataSender is the Thread subclass that DataServer uses to service the clients.

DataReader Class (in DataClient.java)

//*****************************************************************
// This thread class used to monitor the connection to the
// DataServer. It periodically requests data from the server and
// then has DataClient update its display.

class DataReader extends Thread
  {
    String net_line = "";
    boolean keepRunning = true;

    DataClient c;
    //-------------------------------------------------------------     public DataReader(DataClient c) {
      this.c = c;
    }
   //--------------------------------------------------------------

    public void run() {
      String dataString="";
      String histDataString;

      // This loops until either the connection is broken or the
      // stop button or stop key is hit

      while (keepRunning) {

        // Ask the server to send data.
        try{
          c.write_net_output_line("send data");
        }catch (IOException e){
          break;
        }

        // First number sent from server is an integer that gives
        // the number of data values to be sent.

        try{
          c.numData = c.read_net_input_int();
        }catch (IOException e){break;}

        dataString = "Number data pts= " + c.numData + "\n";
        System.out.println(dataString);
        histDataString = "";

        // Create an array to hold the data and then read in the
        // values from the server.

        c.data = new float[c.numData];
        for( int i=0; i < c.numData; i++){
          try{
            c.data[i] = c.read_net_input_float();
            // Pass the data for the monitored channel to the
            // histogram.

            if(i == c.monitorChan) c.hist.setData(c.data[i]);
          }catch (IOException e){break;}

          // BarChart needs data in string form so convert here.
          int j=((int)c.data[i]);
          dataString +=  c.data[i] + " ";
          histDataString += j + " ";
        }
        // Set the data for the TextArea, the event chart.
        c.data_line = dataString + "\n";
        c.chart.setData(histDataString);

        // Now repaint the display.
        c.repaint();

        // Ask for data every TimeUpdate
        try {
          Thread.sleep(c.TimeUpdate);
        } catch (InterruptedException e)
        {}
      }

      c.data_line = dataString + "\n";
      c.msg_line = "disconnected";
      c.repaint();
    }
  }

 

 

 

Home Lectures Resources Index Contacts Students


Physics Simulations with JavaTM
KTH, Kurskod: 5A1418
Curator: Clark S. Lindsey