home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 October A
/
Pcwk10a98.iso
/
Inprise
/
TRIAL
/
JBUILDER
/
JSAMPLES.Z
/
ListenThread.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
3KB
|
89 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.server;
import java.net.*;
import java.io.*;
import java.util.Enumeration;
import borland.samples.apps.chess.client.ServerMessage;
public class ListenThread extends Thread
{
SendThread t;
DataInputStream is;
ServerMessage smsg;
Socket s;
ListenThread(Socket s ,SendThread t) {
this.t = t;
this.s = s;
}
public void run() {
try{
is = new DataInputStream(new BufferedInputStream(s.getInputStream()));
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String inputLine = new String();
int port;
String msgid = new String();
String message = new String();
int offset;
//int blank = 32;
System.out.println("ListenThread - we are listening to " + String.valueOf(t.portnum));
while ((inputLine = br.readLine()) != null && !inputLine.startsWith("Bye ")) {
offset = inputLine.indexOf(' ');
//System.out.println("LT-" + String.valueOf(t.portnum) + " Received:" + inputLine);
if (offset > 0) {
msgid = inputLine.substring(0,offset);
//System.out.println("LT smsg msgid:" + msgid);
message = inputLine.substring(offset+1); //don't store the space
smsg = new ServerMessage(t.portnum,msgid,message);
System.out.println("ListenThread smsg " + String.valueOf(t.portnum) +" msgid:" +
smsg.msgid + "msg:" + smsg.msg);
t.addMsg(smsg);
//synchronized (t) {
// t.msgque.addElement(smsg);
// t.notify();
//}
}
else
System.out.println("ListenThread read weird line" );
}
is.close();
}
catch (IOException e) {
System.out.println("ListenThread " + t.portnum + e );
//e.printStackTrace();
}
catch (Exception e) {
System.out.println("ListenThread " + t.portnum + e );
e.printStackTrace();
}
System.out.println("ListenThread " + t.portnum + "going byebye" );
smsg = new ServerMessage(t.portnum,"dead","");
t.addMsg(smsg);
//synchronized (t) {
// t.msgque.addElement(smsg);
// t.notify();
//}
}
}