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

  1. import java.util.*;
  2. import java.io.*;
  3. import java.net.*;
  4. import multi.*;
  5.  
  6. public class TextPinger {
  7.         static LocalEntity myEntity;
  8.         static World world;
  9.         static TextSender ts;
  10.     public static void main(String[] args) throws IOException, ConnectionRefusedException {
  11.         if (args.length < 7) {
  12.             System.out.println("Usage: java TextPinger host port cname nickname owner pass url");
  13.             System.exit(1);
  14.         }
  15.         world = new World(args[0], Integer.parseInt(args[1]));
  16.         ts = new TextSender(args[0], Integer.parseInt(args[1])+4);
  17.         try { world.identity(args[4], args[5]); }
  18.         catch (BadIdentityException ex) {
  19.             System.out.println("user name and password refused: " + ex);
  20.             System.exit(1);
  21.         }
  22.         myEntity = null;
  23.         try { myEntity = new LocalEntity(world, args[2]); }
  24.         catch (PermissionDeniedException ex) {
  25.             System.out.println("permission denied: " + ex);
  26.             System.exit(0);
  27.         }
  28.         System.out.println("My entity id is " + myEntity.getId());
  29.         myEntity.setNickName(args[3]);
  30.         myEntity.setURL(args[6]);
  31.         myEntity.setTextId(myEntity.getId() + 100);
  32.         ts.setTextId(myEntity.getTextId());
  33.         try { myEntity.updateRegistry(); }
  34.         catch (PermissionDeniedException ex) {
  35.             System.out.println("Couldn't update registry: " + ex);
  36.         }
  37.         new TextThread(myEntity, ts);
  38.     }
  39.  
  40.     static void upd(float x, float y, float z, LocalEntity myEntity) {
  41.         myEntity.setLocation(new Vec3(x, y, z));
  42.         try { myEntity.sendUpdate(); }
  43.         catch (IOException ex) { System.out.print("Could't update: " + ex); }
  44.     }
  45. }
  46.  
  47. class TextThread extends Thread {
  48.     LocalEntity myEntity;
  49.     TextSender textsender;
  50.     int msgnum = 0;
  51.     public TextThread(LocalEntity mye, TextSender ts) {
  52.         myEntity = mye;
  53.         textsender = ts;
  54.         start();
  55.     }
  56.     public void run() {
  57.         while (true) {
  58.             try { textsender.sendText("Message number " + msgnum++); }
  59.             catch (IOException ex) {
  60.                 System.out.println("Couldn't send text message: " + ex);
  61.             }
  62.             try { sleep(2000); }
  63.             catch (InterruptedException ex) { }
  64.         }
  65.     }
  66. }
  67.  
  68.  
  69.