@Override
	public void run() {
		getNetworkHandler().fireNetworkEvent(new NetworkEvent(NetworkEvents.START_SERVER, "Starting server..."));

		// tries to open up a socket on PORT, returns if fail
		if ((serverSocket = setUpServer(port)) == null)
			return;

		setServer(true);
		setClient(false);

		// tries to initiate a connection to the client by accepting incoming
		// connections
		// the accept method listens for incoming connections
		while (listening) {
			clientSocket = listenForIncomingConnections(serverSocket);
			if (clientSocket == null)
				return;
			connectWithClient(clientSocket);
			String clientIp = clientSocket.getRemoteSocketAddress().toString().split("[/:]")[1];
			String localPort = clientSocket.getRemoteSocketAddress().toString().split("[/:]")[2];
			getNetworkHandler().fireNetworkEvent(new NetworkEvent(NetworkEvents.CLIENT_CONNECT, clientIp + " connected on local port " + localPort + "!"));
			setRunning(true);
		}
	}