001 /* 002 * $Id: DefaultReadLoop.java,v 1.1.1.1 2002/06/05 21:56:32 root Exp $ 003 * 004 * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group. 005 * For more information, see <a href="http://www.ai.mit.edu/projects/cs101/">the 006 * CS101 homepage</a> or email <las@ai.mit.edu>. 007 * 008 * Copyright (C) 1996 Massachusetts Institute of Technology. 009 * Please do not redistribute without obtaining permission. 010 */ 011 package cs101.net; 012 013 import java.io.*; 014 015 /** 016 * A generic read loop for a client. 017 * 018 * <P>Copyright (c) 1998 Massachusetts Institute of Technology 019 * 020 * @see cs101.net.Client 021 * 022 * @author Todd C. Parnell, tparnell@ai.mit.edu 023 * @author Lynn Andrea Stein, las@ai.mit.edu 024 * @version $Id: DefaultReadLoop.java,v 1.1.1.1 2002/06/05 21:56:32 root Exp $ 025 */ 026 public class DefaultReadLoop implements Runnable { 027 028 /** Communicates with the network. */ 029 protected Client client; 030 /** Animates this object.*/ 031 protected Thread spirit; 032 033 034 /** 035 * A generic read loop for client. 036 * 037 * @see cs101.net.Client 038 */ 039 public DefaultReadLoop ( Client c ) { 040 this.client = c; 041 this.spirit = new Thread (this); 042 this.spirit.start(); 043 } 044 045 /** 046 * Called by this object's thread. Shouldn't be called otherwise. 047 */ 048 public void run () { 049 BufferedReader in = 050 new BufferedReader(new InputStreamReader(System.in)); 051 while (true) { 052 System.out.println(">>"); 053 System.out.flush(); 054 try { 055 this.client.send( in.readLine() ); 056 } catch (IOException e) {} 057 } 058 } 059 } 060 061 /* 062 * $Log: DefaultReadLoop.java,v $ 063 * Revision 1.1.1.1 2002/06/05 21:56:32 root 064 * CS101 comes to Olin finally. 065 * 066 * Revision 1.5 1998/07/24 17:13:39 tparnell 067 * Placate new javadoc behavior 068 * 069 * Revision 1.4 1998/07/22 18:17:54 tparnell 070 * move from util to net 071 * 072 * Revision 1.3 1998/06/03 21:56:46 tparnell 073 * minor bugfix 074 * 075 * Revision 1.2 1998/06/03 19:28:16 tparnell 076 * update from Java 1.0 to 1.1. 077 * 078 * Revision 1.1 1998/03/13 22:18:11 tparnell 079 * Import from server crash. I think the src and class files match up. 080 * 081 */ 082 083