#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    6
    Rep Power
    0

    Help needed with basic client/server application


    I'm having problems with a basic blackjack program i've been writing. What i hope to achieve is to have the server limit the number of connections to 4 clients. It should check when a new player connects to see if there is an available slot, if there is then it adds it to an array list of currently connected players. It should also check through this list to see if the client is already connected, if so, it should initialise the thread.

    Bizzarely, it does create one instance of the thread if more than one client connects, but then that's it and it refuses to connect current players again (although the server still appears to be running).

    As the thread returns an updated list of players so that disconnections can be taken into account and a slot can be made available for a new player.

    Its terrible code i know, its my first client/server app.

    Rather than stick it all up here, the code can be found at:
    ThreadServer.java - http://stuweb3.cmp.uea.ac.uk/~y0241725/ThreadServer.java
    WinEchoClient.java - http://stuweb3.cmp.uea.ac.uk/~y0241725/WinEchoClient.java
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    6
    Rep Power
    0
    i've also uploaded the Card and Deck classes incase anyone wants to try and compile it.

    Card.java
    Deck.java
  4. #3
  5. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    I'd done some research on this, and if you want to have more than 1 person connected at a time, you need to run multiple threads.
    Java's tutorials cover this. A little searching should turn it up.
  6. #4
  7. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    Resources for learning about threads:
    Java's Thread Tutorial
    JavaWorld: Introduction to Java threads
    IBM: Introduction to Java threads
    Google: java+threads+tutorial

    Comments on this post

    • StevenC agrees : Good links - StevenC
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    6
    Rep Power
    0
    I don't need to have multiple clients connected at once as players take turns in blackjack so running simultaneous threads isn't an issue. The server just needs to make a note of who is connected so that once started, the game keeps the same players
  10. #6
  11. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    I don't need to have multiple clients connected at once as players take turns in blackjack so running simultaneous threads isn't an issue. The server just needs to make a note of who is connected so that once started, the game keeps the same players
    I recommend to re-examine your design. You do need to have multiple clients connected at once in order to maintain your games state, check if a player leaves, if slots are open, etc. Run through those thread tutorials, as it looks like you're a little fuzzy on threaded applications and client/server programs. You may also want to look at the following tutorial. It's for a chat server, but it should give you some ideas on how to facilitate this kind of communication.

    Building a Java chat server
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    6
    Rep Power
    0
    Thanks - i'll take a look at it. Hopefully it'll be better than the other chat program i based it around!

    Looking over it again now though, i've fiddled with it so many times that a full re-write may well be required....

IMN logo majestic logo threadwatch logo seochat tools logo