Network.java :  » Game » openfield » battlefield » net » Java Open Source

Java Open Source » Game » openfield 
openfield » battlefield » net » Network.java
/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =======================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =======================================================
 *   $Id: Network.java 568 2010-07-25 20:56:20Z Harry $
 *   $LastChangedDate: 2010-07-25 13:56:20 -0700 (Sun, 25 Jul 2010) $
 *   $LastChangedBy: Harry $
 *--------------------------------------------------------------------------
 */
package battlefield.net;

import java.net.UnknownHostException;
import java.rmi.RemoteException;
import javax.naming.NamingException;

/**
 *
 * @author Harry Nguyen
 */
public class Network {

    private RmiServer server;
    private RmiClient client;

    public Network() {
    }

    public RmiServer getServer() {
        return server;
    }

    public RmiClient getClient() {
        return client;
    }

    public void startServer() throws RemoteException, NamingException, UnknownHostException {
        server = new RmiServer();
        getServer().startServer();
    }

    public void startClient(String ipAddress) throws NamingException {
        client = new RmiClient();
        getClient().setIpAddress(ipAddress);
        getClient().connectToHost();
    }

    public void stopServer() {
        if (getServer() != null) {
            getServer().stopServer();
        }
    }

    public void stopClient() {
        if (getClient() != null) {
            getClient().stopClient();
        }
    }

    public void stop() {
        stopServer();
        stopClient();
        System.gc();
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.