www.pudn.com > jnp-src.rar > ChatboardClient.java


/*
 * Java Network Programming, Second Edition
 * Merlin Hughes, Michael Shoffner, Derek Hamner
 * Manning Publications Company; ISBN 188477749X
 *
 * http://nitric.com/jnp/
 *
 * Copyright (c) 1997-1999 Merlin Hughes, Michael Shoffner, Derek Hamner;
 * all rights reserved; see license.txt for details.
 */

import java.io.*; 
import java.awt.*; 
 
public class ChatboardClient extends Chatboard implements Client { 
  protected MessageOutput messageOut; 
   
  public void receive (DataInputStream dataIn) { 
    if (messageOut == null) 
      messageOut = super.getMessageOutput (); 
    try { 
      byte[] buffer = new byte[dataIn.available ()]; 
      dataIn.readFully (buffer); 
      messageOut.write (buffer); 
      messageOut.send (); 
    } catch (IOException ex) { 
      ex.printStackTrace (); 
    } 
  } 
 
  public void disconnected () { 
    input.setEditable (false); 
    listener.interrupt (); 
  } 
}