public boolean listenSocket() {

        try {
            server = new ServerSocket(4444);
            System.out.println("server running on port 4444");
        } catch (IOException e) {
            System.out.println("Could not listen on port 4444");
            System.exit(-1);
        }
        //listen for new connections
        while (true) {
            try {
                System.out.println("in while serverlogic");
                //server.accept returns a client connection
                connection = new ServerThread(server.accept());
                System.out.println("new server object created");
                connection.getCredentials();

                //check username and password
                if (isGoodLogin(connection.recievedUsername, connection.recievedPassword, connectedClients) == true) {


                    //create and start new Thread
                    Thread t = new Thread(connection);
                    t.start();

                    //put the username + threadobject in hashmap
                    connectedClients.put(connection.recievedUsername, connection);
                    connection.setRecentHashMap(connectedClients);
                    System.out.println(connectedClients.get(connection.recievedUsername).toString());
                    System.out.println(connectedClients.size());

                    //method to set the recent hashmap of online users for the clients
                    connection.setRecentHashMapForUsers(connectedClients);

                } //new users handling
                else if (connection.recievedUsername.startsWith("new") == true) {
                        String message;
                        
                    if (creationAccount(connection.recievedUsername, connection.recievedPassword) == true)
                        message = "[Success]Account has been created!";
                    else
                        message = "[Error]Account could not be created!";
                    
                    
                        System.out.println(message);
                        connection.out.writeUTF(message);
                        connection.out.flush();
                        
                } else {
                    System.err.println("Bad username or Password...or user already logged in");
                }

            } catch (IOException e) {
                System.out.println("Accept failed: 4444");
                System.exit(-1);
            }
        }
    }