GameClient1.java
import java.net.*;
import java.io.*;
import java.text.*; // for NumberFormat
import java.util.regex.*;
import java.util.*; // for ArrayList, Random
/**
Socket example -- connect, send bogus requests, echo responses.
*/
public class GameClient1
{
public static void main(String[] argv)
{
Packetizer packer = null;
String host = "leipold.ace-net.com";
Random rand = new Random();
try {
Socket sock = new Socket(host,8189);
try {
packer = new Packetizer(sock,new XSBuilder());
packer.start();
}
catch(IOException e_io) {
System.err.println("Can't create Packetizer: " + e_io);
System.exit(1);
}
ArrayList olist = new ArrayList();
olist.add(new Bogus1("Sharon","Chip"));
olist.add(new Bogus2("Walt"));
olist.add(new Bogus1("Dan","Paul"));
olist.add(new Bogus2("Fang"));
olist.add(new NameChanger("Ahab"));
olist.add(new Bogus1("Emily","Alan"));
olist.add(new Bogus2("Beanie"));
olist.add(new Stopper());
for (int i=0; i<olist.size(); i++) {
// Send request.
Object x = olist.get(i);
packer.sendMessage(x);
System.out.println("Sent: " + x);
// Wait for the response.
while (true) {
if (packer.messageAvailable()) {
Object y = packer.readMessage();
System.out.println("Rcvd: " + y);
break;
}
Thread.sleep(10);
}
Thread.sleep(500*rand.nextInt(10));
}
packer.stop();
}
catch (IOException e_io) {
System.out.println("IO exception: " + e_io);
}
catch(InterruptedException e_ie) {
System.err.println("Interrupt: " + e_ie);
}
}
}