Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: anyone into poker?

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default anyone into poker?

    Hi guys,
    I've started developing an on-line poker application as my final project at uni and I need some basic guidance as I can't get my head around some stuff I have some ideas, but i'm not sure how good they are and would appreciate ANY feedback
    So...
    How would you go about the client-server communication?

    Let's say the server hosts two tables( I guess I'll have to use a separate thread for each on of them)
    Then a client connects to the server - this creates another thread(one for each client).
    Then the client chooses a table...and here i'm stuck!! This should start another thread on the client which opens the table window but what d I connect it to and how...? The thread running the table on the server?


  2. #2
    Junior Member
    Join Date
    May 2011
    Posts
    12
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: anyone into poker?

    Everything you're asking for could be done on one thread. However, there are something things you should do before that. One thing I would consider doing is having a Table class that has a fixed number of clients. It could look something like
    public final class Table {
        private final Client[] clients = new Client[7];
     
        public boolean contains(Client client) {
            for (Client c : clients) {
                if (c == client) {
                    return true;
                }
            }
            return false;
        }
     
        public int indexOf(Client client) {
            if (!contains(client)) {
                return -1;
            }
            else {
                for (int i = 0; i < clients.length; i++) {
                    if (clients[i] == client) {
                        return i;
                    }
                }
            }
        }
     
        public void add(Client client) throws IllegalArgumentException,
            FullTableException {
            if (client == null) {
                throw new IllegalArgumentException("client must not be null");
            }
            if (contains(client)) {
                throw new IllegalArgumentException(
                    "cannot add client to the table more than once");
            }
            if (available() > 0) {
                clients[next()] = client;
                // NOTE: You might want to announce to the other players that a new
                // player has joined the game.
            }
            else {
                throw new FullTableException();
            }
        }
     
        public void remove(Client client) throws IllegalArgumentException {
            if (!contains(client)) {
                throw new IllegalArgumentException("table does not contain client");
            }
            clients[indexOf(client)] = null;
            // NOTE: Announce to the other players that the player has left.
        }
     
        private int next() {
            for (int i = 0; i < clients.length; i++) {
                if (clients[i] == null) {
                    return i;
                }
            }
            return -1;
        }
    }

    Another thing you could do is add a "state" to each client, indicating if the client is at a table, in the lobby, etc.

    I would HIGHLY recommend avoiding creating one thread for each client. The more clients connect, the more resources will be used by trying to create a new thread for each one.

    For choosing a table, all you would have to do is have the server send a packet to the client saying which tables are available. Then the client selects one, sends back the table number to the server, which then adds the client to the Table object designated by a certain number. For something as simple as this, I would suggest using the java.net classes. Since each player MUST do an action (call, fold, raise) when it's their turn, having a blocking server should perform just fine.

  3. The Following User Says Thank You to Zymus For This Useful Post:

    Json (May 6th, 2011)

Similar Threads

  1. 2 Player Poker Game Troubles
    By Kaltonse in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 21st, 2010, 12:20 PM
  2. help building up GUI for poker game
    By Pencil in forum AWT / Java Swing
    Replies: 5
    Last Post: October 26th, 2010, 02:53 PM
  3. Replies: 5
    Last Post: June 10th, 2010, 10:19 AM
  4. Please help Me out with this poker Problem
    By ckrisasa in forum Java Networking
    Replies: 1
    Last Post: November 29th, 2009, 01:31 AM