john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

ChatPt3

import java.net.*;
import java.io.*;


public class ChatPt3 {
    private static final int WAITING = 0;
    private static final int ENTERNAME = 1;
    private static final int CHATTING = 2;
    private static final int BYE = 3;
    private static final int WHOIS = 4;

    private int state = WAITING;
    private int clientcount = 0;

    public String processInput(String theInput) throws IOException
    {
        String theOutput = null;

        if(theInput == null);
        {
            System.out.println("Client Connecting...");
            state = WAITING;
        }

        if (state == WAITING)
        {
            theOutput = "Welcome to ChatServe .002, Type in your Chat Name:";

            state = ENTERNAME;
        }
        else if (state == ENTERNAME)
        {

        /*Check Name against userlist

            File userlistFile = null;
            FileWriter outFile = null;
*/
            theOutput = "Don't worry about it.";

            state = CHATTING;

        }
        else if (state == CHATTING)
        {
            if(theInput.equalsIgnoreCase("LOGOFF"))
            {
                state = BYE;
            }
            else if(theInput.equalsIgnoreCase("WHOIS"))
            {
                state = WHOIS;
            }
            else
            {
                theOutput = "testing";
            }

        }
        else if(state == WHOIS)
        {

            theOutput = "not implemented yet";
            state = CHATTING;
/*          int eof;
            File userlistFile = new File("userlist.txt");
            FileReader userlistin = new FileReader(userlistFile);
            while ((eof = userlistin.read()) != -1)
                out.write(c);
*/

        }
        else
        {
            theOutput = "Bye.";
            state = WAITING;
        }

        return theOutput;
    }//processInput method close brace
}//ChatPt2 Class close brace

  • « ChatPt2
  • ChatClient »

Published

Apr 1, 2001

Category

java-chat-university

~149 words

Tags

  • chatcrap 23
  • chatpt3 1