home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch18 / Pinger.java < prev    next >
Text File  |  1997-02-21  |  2KB  |  63 lines

  1. import java.util.*;
  2. import java.io.*;
  3. import multi.*;
  4.  
  5. public class Pinger {
  6.         static LocalEntity myEntity;
  7.         static World world;
  8.     public static void main(String[] args) throws IOException, ConnectionRefusedException {
  9.         if (args.length < 7) {
  10.             System.out.println("Usage: java Pinger host port cname nickname owner pass url");
  11.             System.exit(1);
  12.         }
  13.         world = new World(args[0], Integer.parseInt(args[1]));
  14.         try { world.identity(args[4], args[5]); }
  15.         catch (BadIdentityException ex) {
  16.             System.out.println("user name and passsword refused: " + ex);
  17.             System.exit(1);
  18.         }
  19.         myEntity = null;
  20.         try { myEntity = new LocalEntity(world, args[2]); }
  21.         catch (PermissionDeniedException ex) {
  22.             System.out.println("permission denied: " + ex);
  23.             System.exit(0);
  24.         }
  25.         System.out.println("My entity id is " + myEntity.getId());
  26.         myEntity.setNickName(args[3]);
  27.         myEntity.setURL(args[6]);
  28.         try { myEntity.updateRegistry(); }
  29.         catch (PermissionDeniedException ex) {
  30.             System.out.println("Couldn't update registry: " + ex);
  31.         }
  32. System.out.println("Registry updated");
  33.         new InputThread(myEntity);
  34.     }
  35. }
  36.  
  37. class InputThread extends Thread {
  38.     DataInputStream in;
  39.     LocalEntity myEntity;
  40.     public InputThread(LocalEntity mye) {
  41.         myEntity = mye;
  42.         DataInputStream in = new DataInputStream(System.in);
  43.         start();
  44.     }
  45.     public void run() {
  46.         float distance = 0, step = 1;
  47.         for (int i = 0; i < 20; ++i) {
  48. //        while (true) {
  49.             myEntity.setLocation(new Vec3(distance, 1f, distance));
  50.             distance += step;
  51.             if (distance > 5f) step = -1;
  52.             if (distance < -5f) step = 1;
  53.             try { myEntity.sendUpdate(); }
  54.             catch (IOException ex) { System.out.print("Could't update: " + ex); }
  55. System.out.println("Updated location to " + distance + " " + 1f + " " + distance);
  56.             try { sleep(500); }
  57.             catch (InterruptedException ex) { }
  58.         }
  59.     }
  60. }
  61.  
  62.  
  63.