Results 1 to 9 of 9
  1. #1
    ckrisasa's Avatar
    ckrisasa is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default Please help Me out with this poker Problem

    HOW THE GAME IS PLAYED:

    * The dealer gives 5 cards to each player in the game.
    * The players change some of their cards if they want.
    * The players bets or folds their cards. The bets can be done in any order.
    * The dealer shows the bets of the other players in the game in the order that they were made.
    * When the betting is finished the hands of the players that has not folded their cards are compared to each other and the winner as well as the winning hand is shown to all players by the dealer.



    UseI used the following programs to write my own poker game.

    * PokerServer: Reads in information from the commandprompt and starts the poker server (dealer).
    * PokerImplement: Uses the information from PokerServer, runs the server side of the application and communicates with the poker clients (players).
    * PokerClient: Reads in information from the commandprompt and starts the poker client (player).
    * PokerClientApp: Uses the information from PokerClient, runs the client side of the application and communicates with the poker server (dealer).
    * Cards: Contains the constructors and metods need to create and shuffle a card deck, extract cards from the deck and to determine which of two 5-card hands is the winner.

    * All java files are Zipped here..
    http : / / rapidshare com / files / 312742275 / My_programs.zip [Links are not allowing here..so i fashioned in such a way


    My job in this part is to use to create a multicast group where all the players can recieve the same information from the dealer at once.



    The players must see all the other players requests to change cards and bets in the exact order (Total order) as it came in to the dealer. To achieve this the following must be used:



    * The game will need a sequence number for every message that is incremented by one for every new multicast message. The sequence numbers are used to ensure that request messages are delivered in the same order to all the multicast destinations.
    * A history buffer, which holds a list of messages, already sent to the destinations, together with their sequence numbers.
    * This means that the use of acknowlegment messages is not allowed.


    I should not set sockets' time-to-live (TTL) to more than 1. That way, my multicast packets will not be transmitted beyond the local router.




    I can only run the previously specified programs with the client (player) and server (dealer) on the same computer. Otherwise the parts on the client side that calls methods on the server side will not work yet.


    Please help me out with the program. By finishing this i can get my bachelors completed. I am stuck with this lab. Eventhough i am good at java, i am unable to understand and implement the logic..as per my knowledge i have created some class files. please go through that and give me the complete code that can be executed. I need this favour. If u do so i would be the most happiest person and most thankful to you. You guys can send me source at ghanta dot sairam at live dot com


    Thanking you sir,

    sairam ghanta
    Last edited by ckrisasa; 11-27-2009 at 04:01 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I doubt anyone is going to download your link and wade through your code. You'll be much better off trying to isolate your problems on a smaller scale and asking more direct specific questions here. We do poorly with general "help me finish this program" type questions.

    Much luck.

  3. #3
    ckrisasa's Avatar
    ckrisasa is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    ok..let me put in this way..
    we should use multicasting concept in sending datagram packets and recieving. Communication should be doe based on multicasting...is it possible to make client count dynamically? and to think it seems everything and all compilcated..so i am asking geeks to sort my problem..Most of the code is written..i am asking them to finish it. Thats all...game logic everything is written there...i need communication between server and clients..thats all..So guys, any body who have big heart help me out...i am stuck out with my graduation with this mini project..i want to finish up the things and move to my home country..so i am asking help from java geeks..

  4. #4
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    well, if it works on the same computer, does that that must be using some kind of networking between the dealer server and the player clients already ?

    multicast sockets are for the most part a UDP socket, with the IP address one of the class D designated addresses within the multicast address space 224.0.0.0 - 239.255.255.255, and using the java.net.MulticastSocket for client and server. the idea to make everything be in the same group is to use the same address for client and server.

    For sending message numbers, you would need to do this in the message that you are transferring, such as the dealer server could send a class
    Java Code:
    public class Message implements Serializable {
      int messageNumber;
      String messageType;
      String messageData;
     // and the getters and setters for this property
    }
    where the dealer server would generate the message number from a sequence and build a message bean, and serialize it out to to the multicast socket.

    all of the clients would deserialize the message bean to extract its contents.

    Multicast programming is a bit confusing at first because in this example we are not following the request / response message object paradigm usually found in client-server network programming.

    But a good place to start if you already have the game working and need to bolt in the multicast messaging from the dealer server would be to create a few stand-alone junit or other test cases, that just boots up the multicast sockets in a server (sender) and sends out test messages typical of what it would in the game (such as sleep for a couple seconds, generate a "ping" message, and then have a test client to just receive these packets from the multicast sockets and de-serializing the messages.

    Then when you iron out the kinks with the messaging operation, it should be more natural to integrate this into the poker application.

  5. #5
    ckrisasa's Avatar
    ckrisasa is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    Wow..thanks for your valuable response...can you provide me a sample multicast programing between multiple clients and single server so that server starts transmitting hello message to clients based on requests from clients..here number of clients clients should be decided at runtime.

  6. #6
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    rename the attached .txt file as a .java file.
    its depends on junit and commons-logging
    and i rammed all the classes into one file for posting.

    the server test case just opens up a multicast socket and writes to it, 10 messages in a loop here. the client test starts listening for (also 10 ) test messages. clearly we wouldn't want the real clients to expect the finite number of messages, i just do this to demonstrate the multicast socket writing and reading stuff, though in this case it currently assumes the same single message object is always going to be sent, and from one server sending onto the multicast channel, and that there are no lost packets. in the general case, more than one node could be sending different messages into the same channel, and that is likely more complicated than you need here for the poker server anyway.

    you should be able to launch the individual test methods such as inside eclipse. start off the client(s) first, then the server. there are methods to do a single message, and tests to launch a thread to do the receive messages in a loop.

    that chunking stream stuff is one of my pet experimental things to conveniently allow us to just "send an object" or "receive an object", instead of having to think about stuffing the message within the maximum packet size. the Java datagram socket is 'nice' enough to silently discard and not complain very much if the amount of data to be sent or read happens to exceed the maximum datagram packet size. I like to just have all the packets within the MTU of the network link, so as to increase the chances of all the packets making it and not losing anything by having the data [from a single datagram write] split up over more than one ethernet packet..

    you will see i just create anonymous instances of these chunking streams and implement the get/set content methods which internally do the DatagramPacket work.
    Attached Files Attached Files

  7. #7
    ckrisasa's Avatar
    ckrisasa is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    Wow keep coming your valuable responses.My goodness u r professional in Junit. It will help me alot in future. I have gone through your code. I learned how the multi casting is done in java. I have written my own logic myslef to step into multicasting. Your one seems to be a bit like of mine but having advanced concepts of java like Junit. Mine is old school fashioned student way of programming. Writing classes and creating objects and writing code for them to communicate.

    I want you to help me in a step ahead. Let me put it in this way.

    A game can be played with any number of players. 2,3,4 or 5 and even more. In card game there will be a dealer extra. So lets get me into card game. Here i want to write a dearler and client logic in genric fashion such that dealer should be able to accept any number of clients. if game is played with 2 clients dealer/server should make a count of players as 2 and if game is played with 4 players it should make a count of players as 4. Because based on the count cyclically it should throw 5 cards each to dealer one at a time. If you help me i would be more thankful to you and i will start writing further logic. Give me an idea/throw me a code for the problem i mentioned above.

    Thanks and regards,
    sairam ghanta

  8. #8
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    i woud almost think the business channel between the dealer and the players shoud be a connected TCP socket (not a UDP multicast). I assume the multicast socket is for a broadcast of events as they occur from the dealer server right.

    So the idea of allowing the dealer to know how many players could be handled by maintaining a list of connected TCP socket clients

    Java Code:
    ServerSocket sock = null;
    Vector<Connection> connectedClients = new Vector<Connection>();
    
    public void runServer() {
      try {
          sock = new ServerSocket(port, 0, null);
      }
      catch (IOException ex) {
          return;
      }
      
      System.out.println("tcp server socket thread starting, listening on " + listen + ":" + port);
      
      running = true;
      while (running) {
          try {
              System.out.println("waiting for a connection.");
              Socket clientSock = sock.accept();
              
              System.out.println("new client connected: " + clientSock.getRemoteSocketAddress());
      
              // i invented this class, one thread instance per connected client for its own handler of messages
              ClientConnection c = new ClientConnection(this, clientSock);
    
              connectedClients.add(c);
              
              c.start();
          }
          catch (IOException ex) {
              LOG.error(ex, ex);
          }
       } // while running
    }

    Where the ClientConnection object is a class to store all of the 'state' of a connected client in the server.

    might be something like
    Java Code:
    class ClientConnection extends Thread {
      Socket clientSocket;
      TcpSocketListener parent;
    
      public ClientConnection (TcpSocketListener aParent, Socket aClientSocket) {
          this.parent = aParent;
          this.clientSocket = aClientSocket;
      }
      
      public void run() {
        // stuff that would be done here, like listening for actions from the client
      }
      
      // invoked by the handler from this class  to have this connected client removed from the server's connected list
      public void close() {
        connectedClients.remove(this); 
      }
      
      // maybe a method here to send message (e.g. do a  deal )
      
      
      // but again, we would probably want to define our own high level message object
      // and work to have this message sent back and forth. 
      // (e.g. serialize a bean like we did in the multicast stuff)
      public void sendMessage(MessageBean aMessage) {
        // TODO: this woud be called by the server thread, in a for loop for each connected client
        // but this woud make use of this object's connected socket. 
      }
    }
    So the game operation might try to get the contents of the connectedClients vector (of ClientConnection beans), and do a for(...) each of these, deal a card.

  9. #9
    ckrisasa's Avatar
    ckrisasa is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    this is great. I said to my instructor that it can be done only using tcp socket streaming. But he said that this should be done only using udp datagrams and multicasting...I dont know what to do..Please help me out in multicasting using datagrams.

Similar Threads

  1. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 06:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •