public static void main(String[] args) throws IOException,Exception {
		Socket chSocket = null;
        String adress;
        PrintWriter out = null;
        BufferedReader in = null;
        
        try {
            adress = args[0];
        } catch (ArrayIndexOutOfBoundsException e) {
        	System.err.println("Using localhost.");
        	adress = "127.0.0.1";
        }
        try {
            chSocket = new Socket(adress, connectionPort); 
            out = new PrintWriter(chSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader
                                   (chSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Unknown host: " +adress);
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't open connection to " + adress);
            System.exit(1);
        }
        Scanner scanner = new Scanner(System.in);
        
        String name = "player";
        
        //start with the initial name establishment
        boolean gotname = false;
        //boolean firsttime = true;
        
        while(!gotname) {
        	String serverresponse = in.readLine(); //should be "entername" but we dont care
            if(!serverresponse.equals("reg entername")){
                throw new Exception("Server did not comply to the protocol!");
            }
        	
            //prompt user to enter name:
            System.out.print("Enter name: ");
            name = scanner.nextLine();
        	out.println(name);
        	
        	serverresponse = in.readLine().trim().toLowerCase();
        	String[] tokens = serverresponse.split("\\s+");
        	if(tokens[0].equals("reg") && tokens[1].equals("ok")) {
        		gotname = true;
        	} else {
        		
        		System.out.println("Error occured, message from server:\n");
        		StringBuilder sb = new StringBuilder();
        		for(int i = 2; i < tokens.length;i++) {
        			sb.append(tokens[i] + " ");
        		}
        		System.out.println(sb.toString());
        	}
        	
        }
        
        //now that the name has been set
        Session s = new Session(name);
        
        ClientReceiver cr = new ClientReceiver(in,s);
        ClientSender cs = new ClientSender(out,scanner,s);
        
        s.println("Welcome to the lobby! Type \"list\" to see a list of games! " +
        		"Type \"help\" for information about commands");
        cr.start(); //important to start this one first as it is a new thread!
        
        cs.run();//the current main thread will become the client receiver
        //we will get out of the run method once the user has typed exit.
        //cr.interrupt();
	}