home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / examples / chap05 / MuReceiver.java < prev    next >
Encoding:
Java Source  |  1996-10-07  |  1.2 KB  |  52 lines

  1. // MuReceiver.java
  2. // waiting for avatars' position from server and update them
  3. import vrml.field.*;
  4.  
  5. import java.net.*;
  6. import java.io.*;
  7. import java.util.*;
  8.  
  9. class MuReceiver extends Thread {
  10.    DataInputStream in = null;
  11.    MuClient muclient;
  12.  
  13.    MuReceiver(DataInputStream i, MuClient muc){
  14.       super("MuReceiver");
  15.  
  16.       in = i;
  17.       muclient = muc; // to call methods of MuClient class
  18.       this.start();    // start this thread
  19.    }
  20.  
  21.    public void run(){
  22.       int id;
  23.       int command;
  24.       float x, y, z, r;
  25.  
  26.       while(true){
  27.          try {
  28.         // receive client's id and its position from server
  29.         id = in.readInt();
  30.         command = in.readInt();
  31.         x = in.readFloat();
  32.         y = in.readFloat();
  33.         z = in.readFloat();
  34.  
  35.         if(MuProtocol.MOVE == command){
  36.            // update position 
  37.            muclient.updatePosition(id, x, y, z);
  38.         }else{
  39.            r = in.readFloat();
  40.  
  41.            // update orientation
  42.            muclient.updateOrientation(id, x, y, z, r);
  43.         }
  44.            System.out.println(id + ": " + x + " " + y + " " + z);
  45.          } catch (IOException e) {
  46.          e.printStackTrace();
  47.          return;
  48.          }
  49.       }
  50.    }
  51. }
  52.