home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch18
/
TextPinger.java
< prev
next >
Wrap
Text File
|
1997-02-21
|
2KB
|
69 lines
import java.util.*;
import java.io.*;
import java.net.*;
import multi.*;
public class TextPinger {
static LocalEntity myEntity;
static World world;
static TextSender ts;
public static void main(String[] args) throws IOException, ConnectionRefusedException {
if (args.length < 7) {
System.out.println("Usage: java TextPinger host port cname nickname owner pass url");
System.exit(1);
}
world = new World(args[0], Integer.parseInt(args[1]));
ts = new TextSender(args[0], Integer.parseInt(args[1])+4);
try { world.identity(args[4], args[5]); }
catch (BadIdentityException ex) {
System.out.println("user name and password 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]);
myEntity.setTextId(myEntity.getId() + 100);
ts.setTextId(myEntity.getTextId());
try { myEntity.updateRegistry(); }
catch (PermissionDeniedException ex) {
System.out.println("Couldn't update registry: " + ex);
}
new TextThread(myEntity, ts);
}
static void upd(float x, float y, float z, LocalEntity myEntity) {
myEntity.setLocation(new Vec3(x, y, z));
try { myEntity.sendUpdate(); }
catch (IOException ex) { System.out.print("Could't update: " + ex); }
}
}
class TextThread extends Thread {
LocalEntity myEntity;
TextSender textsender;
int msgnum = 0;
public TextThread(LocalEntity mye, TextSender ts) {
myEntity = mye;
textsender = ts;
start();
}
public void run() {
while (true) {
try { textsender.sendText("Message number " + msgnum++); }
catch (IOException ex) {
System.out.println("Couldn't send text message: " + ex);
}
try { sleep(2000); }
catch (InterruptedException ex) { }
}
}
}