home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
ClientSender.java
< prev
next >
Wrap
Text File
|
1997-07-03
|
2KB
|
56 lines
package borland.samples.apps.chess.client;
import java.net.*;
import java.io.*;
import java.util.*;
import java.net.*;
public class ClientSender extends Thread {
Vector msgque = new Vector(5,5);
Socket kkSocket;
PrintWriter os ;
String id = "Test";
public ClientSender(Socket kkSocket) {
super("Client Sender");
this.kkSocket = kkSocket;
}
public ClientSender() {
super("Client Sender");
}
public synchronized void run() {
try {
os = new PrintWriter(kkSocket.getOutputStream());
//os = new PrintStream(kkSocket.getOutputStream());
//System.out.println("cSend waiting" );
while (true) {
if (msgque.isEmpty()) {
try {
System.out.println("ClientSender waiting");
wait();
}
catch (InterruptedException e){System.out.println("ClientSender woken up");}
}
//System.out.println("cSend got one" );
ServerMessage smsg = (ServerMessage) msgque.firstElement();
System.out.println("ClientSender:" + smsg.msgid + " " + smsg.msg);
msgque.removeElementAt(0);
if (smsg.msgid.equals("Dead"))
break;
else {
os.println(smsg.msgid + " " + smsg.msg);
os.flush();
}
if (smsg.msgid.equals("Bye"))
break;
}
os.close();
}
catch (Exception e) {
System.err.println("cSend " + " Exception: " + e);
}
}
}