/***********************************************************************

GECCO, a platform for command and control gaming

Copyright (C) 2001 Henrik Bäärnhielm, Andreas Enblom, Niklas
Hallenfur, Karl Hasselström, Henrik Hägerström, Oskar Linde, Jing Fu
Zi and Jon Åslund

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.

***********************************************************************/

package gecco.communication.client;

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

/**
 *  This class keeps track of the connection to the server
 *
 * @author     Niklas Hallenfur, Jon Åslund
 * @created    June 27, 2001
 */

public class ServerConnection {
    /**
     *  Description of the Field
     */
    private Socket s;
    /**
     *  Description of the Field
     */
    private BufferedOutputStream out;
    /**
     *  Description of the Field
     */
    private BufferedInputStream in;
    /**
     *  Description of the Field
     */
    private BufferedReader inString;

    /**
     *  Description of the Field
     */
    private DataInputStream data_in;
    /**
     *  Description of the Field
     */
    private DataOutputStream data_out;


    /**
     *  Constructor for the ServerConnection object
     */
    public ServerConnection() {
    }


    /**
     *  Gets the DataOutputStream attribute of the ServerConnection object
     *
     * @return    The DataOutputStream value
     */
    public DataOutputStream getDataOutputStream() {
        return data_out;
    }


    /**
     *  Gets the DataInputStream attribute of the ServerConnection object
     *
     * @return    The DataInputStream value
     */
    public DataInputStream getDataInputStream() {
        return data_in;
    }


    /**
     *  Tries to connect to a server
     *
     * @param  port           the port to connect to
     * @param  hostname       Description of Parameter
     * @exception  Exception  Description of Exception
     */
    public void connectToServer(String hostname, int port) throws Exception {
        try {
            InetAddress host = InetAddress.getByName(hostname);
            Socket s = new Socket(host, port);
            in = new BufferedInputStream(s.getInputStream(), 16384);
            out = new BufferedOutputStream(s.getOutputStream(), 16384);

            data_in = new DataInputStream(in);
            data_out = new DataOutputStream(out);

            inString = new BufferedReader(new InputStreamReader(
                    s.getInputStream()));
        } catch (Exception e) {
            throw e;
        }
    }
}












