/* * * FileName: ReadClient.java * * * $Author: konki $ * Author(s): konki * * * Objective: network * * * $Log: ReadClient.java,v $ # Revision 1.3 1996/04/01 21:30:51 konki # Took care of ODELETE message # # Revision 1.2 1996/02/21 00:26:43 konki # Added Comments # # Revision 1.1 1996/02/18 23:10:37 konki # Initial revision # * Change Log: * Created on Thu Feb 1 14:17:00 EST 1996 * Changes: Date Initials * * * Functions: * * * Notes: * $Id: ReadClient.java,v 1.3 1996/04/01 21:30:51 konki Exp $ * */ package wb; import java.io.*; import java.net.*; import java.lang.*; import java.util.*; /** * ReadClient is spawned thread from the server (Listen) which handles all the * reading associated with a specific participant for the user. It handles all * the message/GraphUnit unpack'g and processes them appropriately. * Based on the MESSAGE ID, and the information packed in the message, the remote * user is verified before being accepted. */ public class ReadClient implements Runnable, GTypes { /** * Current Thread */ Thread t = null; /** * Current connection Socket from which data is read. */ Socket con = null; /** * DataInputStream associated with the Socket from which data is read. */ DataInputStream in = null; /** * WBCanvas onto which the Graphic Object is rendered */ WBCanvas can = null; /** * Pointer or reference to the Participants of this WhiteBoard */ Participants partylist = null; /** * Pointer or reference to the User associated with this socket */ UserInfo ux = null; /** * Creates a ReadClient instance. A thread that either lasts for the whole * conference or receives the message and and disconnected. * @param passed Socket associated with this user. * @param arg WBCanvas onto which the GraphUnits are rendered. */ public ReadClient(Socket passed, WBCanvas arg) { con = passed != null ? passed : null; can = arg != null ? arg : null; } /** * Creates a ReadClient instance. A thread that either lasts for the whole * conference or receives the message and and disconnected. * @param passed Socket associated with this user. * @param arg WBCanvas onto which the GraphUnits are rendered. * @param party Participants instance reference of this Session */ public ReadClient(Socket passed, WBCanvas arg, Participants party) { con = passed != null ? passed : null; can = arg != null ? arg : null; partylist = party; } /** * sets the Participants reference. Must be called before the thread is * started. * @param party the Participants */ public void setParticipants( Participants party ) { partylist = party; } /** * Starts this thread. * Reads the message on this socket and verifies the user, and appropriately * terminates or continues this thread. */ public void start() { if ( con == null && can == null ) { return; } try { in = new DataInputStream(con.getInputStream()); int type = in.readInt(); Message mu = new Message( in ); switch(mu.gettype()) { case WBJOIN: case CMJOIN: StringTokenizer st = new StringTokenizer(mu.getMessage()); String uname = st.nextToken("@"); String hname = st.nextToken(); if ( !partylist.CheckUser(uname+hname)) { ux = new UserInfo( partylist.lusername, partylist.lhostname, uname, hname ); partylist.AddUser(ux); if ( mu.gettype() == CMJOIN) { try { con.close(); in.close(); } catch ( Exception any){ } finally { return; } } ux.setInStream(in); ux.setInSocket(con); ux.Connected(); // Handle Initialization of client screen. } break; case START: default: ux = partylist.GetUser(mu.getMessage()); if ( ux != null ) { ux.setInStream(in); ux.setInSocket(con); ux.Connected(); } else { return; } break; } } catch ( Exception excep ) { return; } if (t == null) { t = new Thread(this); t.setPriority(Thread.NORM_PRIORITY); t.start(); } } /** * Stops this thread. * It sets the state of the user to disconnected and closes the socket * and the data stream associated */ public void stop() { if (t != null) { if ( ux != null ) ux.DisConnected(); try { in.close(); con.close(); } catch ( Exception excep ) {} t.stop(); t = null; } } /** * Joins this thread. * @exception java.lang.InterruptedException when join fails */ public final void join() throws java.lang.InterruptedException { try { if (t != null) { t.join(); } } catch(InterruptedException e) { throw e; } return; } /** * Runs this thread. * return from this would mean an end of this thread. */ public void run() { int type = -1; GraphUnit gu = null; Message mu = null; if (t == null || con == null || can == null ) { return; } while( t != null ) { try{ type = in.readInt(); switch( type ) { case OVALS: gu = new GraphOval( in ); break; case RECTS: gu = new GraphRect( in ); break; case LINES: gu = new GraphLine( in ); break; case RDRECTS: gu = new GraphRRect( in ); break; case POINTS: gu = new GFreeHand( in ); break; case TEXTS: gu = new GraphText( in ); break; case POLYS: gu = new GraphPolyLine( in ); break; case SPOKES: gu = new GraphSpoke( in ); break; case MARKERS: gu = new GCrossMarker( in ); break; case QUESTION: gu = new GQuestMarker( in ); break; case START: gu = new Message( in ); break; case ODELETE: gu = new Message( in ); break; case OCLEAR: gu = new Message( in ); break; default: gu = null; } } catch( IOException excep ) { if ( excep instanceof InterruptedIOException ) { gu = null; } else if ( excep instanceof EOFException ) { gu = null; stop(); return; } } finally { if ( gu != null) { can.Add(gu, ux.username+ux.hostname); gu = null; } } } } } /* * End of file ReadClient.java */