home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
ClientSender.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
2KB
|
75 lines
/*
* Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland as part
* of a Borland product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
* COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
* OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
* OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
* OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
* OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
* CODE FILE.
*/
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(ServerMessage.DEAD))
break;
else {
os.println(smsg.msgid + " " + smsg.msg);
os.flush();
}
if (smsg.msgid.equals(ServerMessage.BYE))
break;
}
os.close();
}
catch (Exception e) {
System.err.println("cSend " + " Exception: " + e);
}
}
}