//   Course Number: COSC 650 Data Comm/Networks
//    Program Name: JavaChat
//  Project Number: 2
//         Authors: Brian Hoffman
//                  Mike McKinney
//                  Javier Carrasco
//     Description: This class is used by the server to represent data about 
//                  each client it is connected to.

import java.net.*;   //package required for socket connection
import java.io.*;

public class ChatClient {
    
    private String username;
    private Socket socket;
    private ObjectOutputStream objOut;
    private ObjectInputStream objIn;
    
    /**
     * ------------------------------------------------------------------------
     * default constructor - creates a new instance of ChatClient
     * ------------------------------------------------------------------------
     */
    public ChatClient()
    { }

    /**
     * ------------------------------------------------------------------------
     * parameter constructor
     * ------------------------------------------------------------------------
     */
    public ChatClient(String userNew, Socket socketNew, ObjectOutputStream objOutNew,
                      ObjectInputStream objInNew)
    {
        username = userNew;
        socket = socketNew;
        objOut = objOutNew;
        objIn = objInNew;
    } 
  

    /**
     * ------------------------------------------------------------------------
     * Writes ChatMessage message to the ChatClients output stream
     * ------------------------------------------------------------------------
     */
    public synchronized void sendMessage(ChatMessage message)
    {
        try {
            objOut.writeObject(message);
            objOut.flush();
        }
        catch (IOException e) {
            System.out.println("Unable to write to socket stream(" + this.getUser() + ")");
        }
    }
    
    /**
     * ------------------------------------------------------------------------
     * Returns the username of the ChatClient
     * ------------------------------------------------------------------------
     */
    public String getUser()
    {
        return(username);
    }
    
    /**
     * ------------------------------------------------------------------------
     * Returns the socket for the ChatClient
     * ------------------------------------------------------------------------
     */
    public Socket getSocket()
    {
        return(socket);
    }

}
