home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch18
/
Pinger.java
< prev
next >
Wrap
Text File
|
1997-02-21
|
2KB
|
63 lines
import java.util.*;
import java.io.*;
import multi.*;
public class Pinger {
static LocalEntity myEntity;
static World world;
public static void main(String[] args) throws IOException, ConnectionRefusedException {
if (args.length < 7) {
System.out.println("Usage: java Pinger host port cname nickname owner pass url");
System.exit(1);
}
world = new World(args[0], Integer.parseInt(args[1]));
try { world.identity(args[4], args[5]); }
catch (BadIdentityException ex) {
System.out.println("user name and passsword refused: " + ex);
System.exit(1);
}
myEntity = null;
try { myEntity = new LocalEntity(world, args[2]); }
catch (PermissionDeniedException ex) {
System.out.println("permission denied: " + ex);
System.exit(0);
}
System.out.println("My entity id is " + myEntity.getId());
myEntity.setNickName(args[3]);
myEntity.setURL(args[6]);
try { myEntity.updateRegistry(); }
catch (PermissionDeniedException ex) {
System.out.println("Couldn't update registry: " + ex);
}
System.out.println("Registry updated");
new InputThread(myEntity);
}
}
class InputThread extends Thread {
DataInputStream in;
LocalEntity myEntity;
public InputThread(LocalEntity mye) {
myEntity = mye;
DataInputStream in = new DataInputStream(System.in);
start();
}
public void run() {
float distance = 0, step = 1;
for (int i = 0; i < 20; ++i) {
// while (true) {
myEntity.setLocation(new Vec3(distance, 1f, distance));
distance += step;
if (distance > 5f) step = -1;
if (distance < -5f) step = 1;
try { myEntity.sendUpdate(); }
catch (IOException ex) { System.out.print("Could't update: " + ex); }
System.out.println("Updated location to " + distance + " " + 1f + " " + distance);
try { sleep(500); }
catch (InterruptedException ex) { }
}
}
}