Help Needed With Basic Client/Server App

I was wondering if anyone can help with a simple blackjack client/server application i've been writting (basically its a moddified chat application). The problem i'm having seems to lie within the connection management i've written.
What i'm trying to get is that only 4 players can connect at one time and that each player takes a turn (which i've implemented using threads) to play their hand (as you would if you were playing it for real). The problem is that it will allow the players to connect, but oddly enough, it will not allow a new transaction to be created (i.e. allow a player to take their turn) until 2 players have connected.
Even when it does create the transaction, after taking input from the client once, the server seems to stop doing anything without any error message of any kind.
Its really annoyed me now, so you guys are my last hope!
The code can be found in full here:
Client Application: http://stuweb3.cmp.uea.ac.uk/~y0241725/WinEchoClient.java
Server Application: http://stuweb3.cmp.uea.ac.uk/~y0241725/ThreadServer.java
Card Class: http://stuweb3.cmp.uea.ac.uk/~y0241725/Card.java
Deck Class: http://stuweb3.cmp.uea.ac.uk/~y0241725/Deck.java
Please feel free to play around with this code as much as you feel necessary!

(one last bump back up the forum before i give up on this completely)

Similar Messages

  • Help needed regarding the client server communication

    this is regarding my networking project which at present i am doing it in java...
    the project is abt establishing a server in my lab that controls all the other systems in that lab... now the problem is i have to shut down all the systems in the lab from the server on a click of a button.... this i need to do using socket programming to which i am new....
    So can anyone pls send me a sample code as to how to pass a command from server to shut shut down all the systems(clients) ..i need a java program that uses sockets concept to perform the above mentioned operation...pls note i am trying to establish a linux server
    regards
    lalita

    Dear hiwa
    i can use it but the constraint in my project is to use only the Socket programming due to time lacks.... i have to find a faster way to communicate between the server and the client...
    can u pls help me find a solution for this via sockets...
    hoping a favorable response
    regards
    Lalita

  • Help needed with basic implementation of drawrect: in NSView

    i've read the sections concerning the above in the "view guides for cocoa" docs, as well as several tutorials, but for the life of me i can't figure out how to do a very simple thing.
    all the examples i've seen explain how to use NSRect and NSBezierPath, with fills and strokes, *from within* the drawRect: method. but i want to pass a custom object as a method argument to the view object (say, from inside my controller object when a user presses a button), and then write the code needed to run some getters on the object and draw some stuff accordingly.
    i've defined the view as follows in the controller class header:
    MyCustomNSViewSubclass *theView;
    now i just want to send that view a message like this:
    [theView draw: myObject]
    then i just want to add the code in the view class to do find out some things about myObject and then draw some lines. i just don't understand where to put that code and how the drawRect: method gets called. writing a method like this in the MyCustomNSViewSubclass implementation (which is instanced in "theView") doesn't help:
    - (void) draw: (myObjectType *) anObject
    because then i can't figure what's needed to actually update the view.
    i understand i must be using a wrong approach here. any help will be much appreciated.
    thanks.

    No no, you didn't really understand : you are the developer, you do whatever you want, it means that if you want your custom NSView to simply ask other object to draw their own contents and do nothing else in the NSView you can, but if you want your NSView to manage everything you can too...
    For example, let say I want a Shape class to manage... Shapes in my views... That's not very useful since there's already the NSBezierPath class that allows you to draw a lot of things, but whatever.
    That shape class is very simple, it can represent either a rectangle or a circle and it can draw itself. There's the possible implementation :
    // Shape.h
    #import <Cocoa/Cocoa.h>
    @interface Shape : NSObject
    NSRect rect;
    NSColor *fillColor;
    NSColor *strokeColor;
    BOOL isCircle;
    - (void)setRect:(NSRect)aRect;
    - (void)setFillColor:(NSColor *)aColor;
    - (void)setStrokeColor:(NSColor *)aColor;
    - (void)setIsCircle:(BOOL)flag;
    - (void)draw;
    @end
    // Shape.m
    #import "Shape.h"
    @implementation Shape
    - (void)setRect:(NSRect)aRect
    rect = aRect;
    - (void)setFillColor:(NSColor *)aColor
    if(fillColor != aColor)
    [fillColor release];
    fillColor = [aColor retain];
    - (void)setStrokeColor:(NSColor *)aColor
    if(strokeColor != aColor)
    [strokeColor release];
    strokeColor = [aColor retain];
    - (void)setIsCircle:(BOOL)flag
    isCircle = flag;
    - (void)draw
    NSBezierPath *temp;
    if(isCircle)
    temp = [NSBezierPath bezierPathWithOvalInRect:rect];
    else
    temp = [NSBezierPath bezierPathWithRect:rect];
    [fillColor set];
    [temp fill];
    [strokeColor set];
    [temp stroke];
    - (void) dealloc
    [fillColor release];
    [strokeColor release];
    [super dealloc];
    @end
    That's a very simple class, there's not even an initializer... But it's not the problem here... What we want here it's a self-drown object. You see that class is a subclass of NSObject, nothing special.
    Let see now our custom NSView class, which means a subclass of NSView :
    // MyView.h
    #import <Cocoa/Cocoa.h>
    @class Shape;
    @interface MyView : NSView
    NSMutableArray *shapesToDraw;
    - (void)addShape:(Shape *)aShape;
    - (void)removeShapeAtIndex:(unsigned)index;
    @end
    // MyView.m
    #import "MyView.h"
    #import "Shape.h"
    @implementation MyView
    - (id)initWithFrame:(NSRect)frame
    self = [super initWithFrame:frame];
    if (self)
    // Here we simply create a new array that will contain our shapes to draw
    shapesToDraw = [[NSMutableArray array] retain];
    return self;
    - (void)drawRect:(NSRect)rect
    // This code simply asks to every shape in the array to draw itself
    NSEnumerator *e = [shapesToDraw objectEnumerator];
    Shape *shape = nil;
    while(shape = [e nextObject])
    [shape draw];
    - (void)addShape:(Shape *)aShape
    [shapesToDraw addObject:aShape];
    // When the content of the array changes, we need to tell the view
    // to redraw itself, we do with that message
    [self setNeedsDisplay:YES];
    - (void)removeShapeAtIndex:(unsigned)index
    [shapesToDraw removeObjectAtIndex:index];
    [self setNeedsDisplay:YES];
    - (void) dealloc
    [shapesToDraw release];
    [super dealloc];
    @end
    So you see here, how do you draw objects ? Well, first you need to know them, you also need them to know how to draw themselves... In Cocoa that kind of object already exists, they're NSBezierPath, when you send the message -fill or -stroke you ask them to draw themselves with the current color.
    Here, each shape will be asked one after another to draw itself in the rectangle that is defined in it. You can add a shape by creating it in a controller for example, and add it using the add method I defined, here the drawing code is actually in both classes, in fact we can consider [shape draw] as being "drawing code", that' a point to get : You can't draw outside a -drawRect: method (except in certain complex cases), but you can send messages that contains drawing code within -drawRect: to other objects. that's what I do here.
    However, you need to know that an NSView doesn't only manage its drawings, it also receives events like a click of the mouse or a typed key, there's methods to manage that into the view, and if all the code of an application is inside your view class, well your code might get really big and very difficult to read, that's why we cut in smaller parts to make it easier to read and to understand.
    So, do whatever you want in that -drawRect: method, you know, here I put a -draw method into the Shape class, but I could also have put method to get the NSRect value, the fill color, the stroke color and the kind of shape and make the drawing code directly in the view. You can do whatever you want.
    So, to summarize, you don't "send" objects for your view to draw. The view draws what the -drawRect: methods draws, and not more so if you want your view to draw custom paths, you can use the technic I gave you, that is for example you put a NSMutableArray into your view and create a ColoredPath class that own an NSBezierPath and two NSColor (fill and stroke) and you define a -draw method that your view will call on each ColoredPath objects that the array contains.
    That's a work around. But depending in what you actually want to do, there's a lot of different solutions.
    Now, talking about the interface problem. In IB when you drag a custom view on the window, by default that object is set to NSView, so you need to make it an instance of your own view subclass.
    If you're under Leopard with Xcode 3 and IB 3, in IB you click on your view and go in Identify Inspector (cmd + 6) you type the name of your subclass in the Class field, if you already created the class files, the name should appear before you finished.
    If you're under Xcode 2 and IB 2, you go in the Custom Class Inspector (also cmd + 6) and you select your custom class in the list.
    The name of your class should replace the "Custom Class" label on the view.
    That's how you set the class of a view in IB and make your app call your code when the view needs to display.

  • AEBS help needed with basics..

    Hi Guys
    I am thinking of buying an AEBS and have a few questions. I have been reading through these forums trying to find an answer for my questions but they seem a little confusing. I know this has been asked before but know one seems to be able to give a straight answer.
    Anyhow
    I have recently purchased a Mac book Pro (My first Mac) my wife has a Sony laptop running Vista. We have a printer and HDD and would like to set them up wirelessly and access them on both machines. Im sure this is possible with a AEBS.
    I would also like both systems to backup wirelessly, to the same HDD, (I think this is where it gets confusing) is this possible? If so what would I need to do?
    Any help you guys can give to clear this up would be appreciated.
    Thanks

    I would also like both systems to backup wirelessly, to the same HDD, (I think this is where it gets confusing) is this possible? If so what would I need to do?
    Yes, this is possible.
    The key is the backup solution must support backing up to a network drive.
    For the Mac, you would want to use Time Machine; however, at this time Apple does not support TM backups to AirPort Disks (drives connected to the AEBS's USB port) ... so you would need to look into another backup solutions. (ref: Mac OS X 10.5: Time Machine doesn't back up to AirPort Extreme AirPort Disks) One of those solutions could be EMC's Retrospect 8 Desktop 3 User
    For the PC there are a number of backup solutions that support backups to network drives. One that comes to mind is Genie - Soft's Genie Backup Manager Home.

  • PLEASE HELP me with my Client/Server problem !!!

    I have a method that can currently only recieve one file at a time, but I need it to be able to recieve multiple incomming files. My problem is that it can recieve the first file, but when the send file is sent to this method, it freezes. Can somebody please help me debug it!! I need to get this working by tonight. Thanks!
    public class A implements Runnable {
            String hostname;
            private Thread runner;
            public A () {}
            public void receive() throws IOException {
                    try {
                            while (true) {
                                    Socket s = ss.accept();            
                                    s.close();
                    } catch (Exception e) {
                            System.out.println(e);
            public void run() {
                    try {
                            ServerSocket ss = new ServerSocket(1111);
                            while (true) {
                                    receive();
                    } catch (IOException ioe) {
                            System.out.println("IOException in run()\n" + ioe.getMessage());
            private void stop() {Runner = null;}
            public void request(String fileName) {
                    if(runner == null) {
                   runner = new Thread(this);
                   runner.start();
                            try {
                                    send(fileName);
                            } catch (Exception e) {
                                System.out.println("Exception in run()\n" + e.getMessage());
    }

    you have a while(true) in your receive, so you accept the socket, do the // ... stuff, close it, and then sit there waiting to accept another one again. Am I seeing that correctly?

  • Help needed with basic program

    I am working on an assignment for my java class, and I am stuck. This is the 1st programming class that i have taken and am a little confused. I am supposed to write a program that inputs 5 numbers and determines and prints the number of negative numbers, positive numbers, and zeros that were inputed. I have gone about this a few different ways so far... but I'm not really sure what to do...
    This is what I have so far on my latest attempt, which I think might be completely wrong..... HELP!!!
    import java.util.Scanner;
    public class test
         public static void main (String[] args)
         Scanner input = new Scanner (System.in);
         int integer
         int negative = 0;
         int positive = 0;
         int zero = 0;
         int studentCounter = 1;
         while (studentCounter <=5)
         System.out.print("Please enter an integer:");
         integer = input.nextInt();
         if (integer == 0
              zero = zero +1
    I also tried something similar using :
         int num1; //first number input     
         int num2; //second number input
         int num3; //third number input
         int num4; //forth number input
         int num5; //fifth number input
    System.out.print ("Enter first integer:"); //prompts for input
         num1 = input.nextInt();
         System.out.print ("Enter second integer:"); //prompts for input
         num2 = input.nextInt();
         System.out.print ("Enter third integer:"); //prompts for input
         num3 = input.nextInt();
         System.out.print ("Enter forth integer:"); //prompts for input
         num4 = input.nextInt();
         System.out.print ("Enter fifth integer:"); //prompts for input
         num5 = input.nextInt();
    but i didn't know what to do next.....

    import java.util.Scanner;
    ublic class test
         public static void main (String[] args)
         Scanner input = new Scanner (System.in);
    int integer
    int negative = 0;
    int positive = 0;
         int zero = 0;
    int studentCounter = 1;
    while (studentCounter <=5)
         System.out.print("Please enter an integer:");
         integer = input.nextInt();
    if (integer == 0
              zero = zero +1
    This looks more or less correct so far. Not ideal, but aside from a missing ) and the fact that you trailed off without finishing, it looks like you're on track.
    Start with this, and post details about what specific problems you're having.
    When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.

  • Help needed with basic Terminal command

    Hey there guys! Recently I decided to install SSD on my Mac Pro. Of course SSD is not spacious enough to store all my files, so I found a good solution on the web which involves a little bit of basic Terminal knowledge - http://mattgemmell.com/using-os-x-with-an-ssd-plus-hdd-setup/
    In the article its said :
    - In the Finder, copy the folder from SSD to the HDD. Check that it was copied successfully.
    - In Terminal, 'cd' to the location of the original folder (on the SSD), and delete it via 'sudo rm -rf foldername'.
    - in Terminal, still in the location of the original folder you just deleted, make a link to the copy of the folder on the HDD, via 'ln -s /Volumes/HDDname/path/to/foldername'.
    What Im struggling with is what 'cd' means and what is meant by - 'still in the location of the original folder'?
    I would appreciate if someone could explain to a noob how to create SDD+HDD setup mentioned in article.

    cd means change directory.
    - means options to the command follow.
    The options listed for the Remove command are Recursive and Force.
    Recursive means traverse all subdirectories and delete the files in there, too, then finish by deleting the listed directory. Force means do it no matter what.
    still in the location of the original folder
    means, don't change directories. You must be in the original folder's directory when you run the Link command as listed.
    Some other options to your problem:
    Move your entire Home folder (better): os x move home folder
    Create your own Fusion Drive (sketchy): http://www.macworld.com/article/2014011/how-to-make-your-own-fusion-drive.html

  • Little help needed with the installation of apps...

    Before the I was told to update to 3.0 I purchased and downloaded a few apps, using my iphone.
    Where can I download them without being charged again?
    The 'Application' tab in iTunes isn't there :S

    "Where can I download them without being charged again?"
    Itunes.

  • How to reset the wiki server (MAC OS X 10.9 with OS X Server App Version 3) with all wiki datas only

    Hi,
    I need to reset my Wiki on MAC OS X 10.9 with OS X Server App Version 3, but without reinstalling the whole server app to configure all services.
    Does anybody knows how to reset the wiki server (MAC OS X 10.9 with OS X Server App Version 3) with all wiki datas only.
    Thanks a lot for your hints

    Hi Linc,
    sorry, I haven't saved the System-Logfile before restoring my parallels VM.
    But it looks like issues of linking data.
    For testing the Server services I have done a reset for a user password and I have deleted the profiles and configuration from Client-Side. One with Mac OS X 10.9.1, one iPad with iOS 6.1.3. But it was not possible to reconfigure/reinstall the Server Profile. Also a manually configuration was odd, because for some services the new password was necessary and for other services the old password. Very strange.
    To bring back the services I have rolled back the last snapshot of my parallels VM. Afterwards there was no probleme to reconfigure/reinstall the Profile on Client-Side (OS X 10.9.1 and iOS 6.1.3). Also the manually configuration shows the password for all services are matching with the current configuration.
    I'm going to install a further parallels VM with Mac OS X 10.9.1 and Server App 3 from scratch to move the services.
    Greetings

  • Help needed with itunes

    help needed with itunes please tryed to move my itunes libary to my external hard drive itunes move ok and runs fin but i have none of my music or apps or anything all my stuff is in the itunes folder on my external hard drive but there is nothing on ituns how do i get it back help,please

    (Make sure the Music (top left) library is selected before beginning this.)
    If you have bad song links in your library, hilite them and hit the delete button. Then locate the folder(s) where your music is located and drag and drop into the large library window in iTunes ( where your tracks show up). This will force the tunes into iTunes. Before you start, check your preferences in iTunes specifically under the"Advanced" tab, general settings. I prefer that the 1st 2 boxes are unchecked. (Keep iTunes Music folder organized & Copy files to iTunes Music folder when adding to library). They are designed to let iTunes manage your library. I prefer to manage it myself. Suit yourself. If there is a way for iTunes to restore broken links other than locating one song at a time I haven't found it yet. (I wish Apple would fix this, as I have used that feature in other apps.) This is the way I do it and I have approx. 25,000 songs and podcasts and videos at present. Hope this helps.

  • Urgent help needed with un-removable junk mail that froze Mail!!

    Urgent help needed with un-removable junk mail that froze Mail?
    I had 7 junk mails come in this morning, 5 went straight to junk and 2 more I junked.
    When I clicked on the Junk folder to empty it, it froze Mail and I can't click on anything, I had to force quit Mail and re-open it. When it re-opens the Junk folder is selected and it is froze, I can't do anything.
    I repaired permissions, it did nothing.
    I re-booted my computer, on opening Mail the In folder was selected, when I selected Junk, again, it locks up Mail and I can't select them to delete them?
    Anyone know how I can delete these Junk mails from my Junk folder without having to open Mail to do it as it would appear this will be the only solution to the problem.

    Hi Nigel
    If you hold the Shift key when opening the mail app, it will start up without any folders selected & no emails showing. Hopefully this will enable you to start Mail ok.
    Then from the Mail menus - choose Mailbox-Erase Junk Mail . The problem mail should now be in the trash. If there's nothing you want to retain from the Trash, you should now choose Mailbox- Erase Deleted Messages....
    If you need to double-check the Trash for anything you might want to retain, then view the Trash folder first, before using Erase Junk Mail & move anything you wish to keep to another folder.
    The shift key starts Mail in a sort of Safe mode.

  • Help needed with this form in DW

    Hi, i have created this form in dreamweaver but ive got this problem.
    In the fields above the text field, the client needs to fill in some info such as name, email telephone number etc.
    But the problem is when ill get the messages. Only the text from the large text field is there.
    What did i do wrong??
    http://www.hureninparamaribo.nl/contact.html
    Thank you
    Anybody??

    Thank you for your response. So what do i have to do to fix this?
    Date: Sun, 20 Jan 2013 07:57:56 -0700
    From: [email protected]
    To: [email protected]
    Subject: Help needed with this form in DW
        Re: Help needed with this form in DW
        created by Ken Binney in Dreamweaver General - View the full discussion
    You have several duplicate "name" attributes in these rows which also appears in the first row
    Telefoon:
    Huurperiode:
    Aantal personen:
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5008247#5008247
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5008247#5008247
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5008247#5008247. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Dreamweaver General by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Help needed with a chat program

    Hi everyone! i'm busy with a client/server chat program. I'm really stuck because i can't seem to get the messages from one client to show on the other client's screen.
    If one client sends a message to another client, the server receives the message, but the second client does not receive the message.
    Here is the server code that sends messages to the clients:
    BufferedReader incomeReader = null;
    PrintWriter outWriter = null;
    try {
         incomeReader = new BufferedReader(new InputStreamReader (incomingSocket.getInputStream()));
    outWriter = new PrintWriter(incomingSocket.getOutputStream(),true);
    }catch (Exception e) {
              System.out.println("error handling a client: " + e);
    System.exit(-1);
    line = incomeReader.readLine();
    textArea.append(line + "\n");               
    outWriter.println(line);
    The server is suppose to put the message it receives on the text area on the server screen, and then send the message to all clients connected to it.
    I hope somebody will be able to help me...

    The code posted just sends any data it receives back to the person who sent it. To get it to work there, you probably should flush after the println. I believe your mother taught you always to flush. It seems you have forgotten.

  • How to design socket client-server app for 2-way communication

    Hi, I am writing a client-server application. I have a single server and many clients. Each client will need the ability to send information to the server at any time. The server will also need the ability to send information to a client at any time. Its this second part that I am not sure how to design. Would I need to create a SocketServer on each client to accept incoming messages, or is there a better way? Thanks

    scranchdaddy wrote:
    Don't my requirements sound a lot like an IM application, where a chat server might need to send a message to a chat client at any time?Not really. If that is what you are designing
    in my opinion one could easily be forgiven for thinking you were deliberately obfuscating your goal...
    How does the server know where the client is? Does it know the IP address of the client?I would imagine the server would contain a directory of IPs? I'm not sure.
    What happens if the client is not running?Then I guess the message would not get delivered.
    What happens if the client is behind a firewall that does not allow incoming connections?How do IM chat clients work? How have people solved this in the past?Typically the server would only care about clients currently connected to the server.
    Maybe you should re-think your design. I don't really have a design, just requirements, that's why I'm writing this post.Your subject says "+How to *design* socket client-server app for 2-way communication+".
    Are you saying you expect someone else to do the design for you?

  • HELP NEEDED WITH ADDAPTER-DVI TO VGA.

    PLEASE ...HELP NEEDED WITH WIRING CROSS OVER....CAN YOU HELP WITH BACK OF PLUG CONNECTIONS...I SORTA UNDERSTAND THE PINOUTS BUT CANT MAKE AN EXACT MACH...WOULD LIKE TO BE 100% SURE...
    ......THIS ENSURES NO SMOKE!!!                                                                                           
    THE CARD IS AN ATI RADEON RX9250-DUAL HEAD-.........ADDAPTER IS DVI(ANALOG)MALE TO VGA(ANALOG)FEMALE.
    ANY HELP VERY MUCH APPRECIATED........ SEEMS YOU NEED TO BE ROCKET SCI TO ATTACH A BLOODY PICTURE...SO THIS HAS BEEN BIG WASTE OF FING TIME!

    Quote from: BOBHIGH on 17-December-05, 09:21:31
    Get over it mate !
    I find it easy t read CAPS...and if you dont like it ...DONT READ IT!
    And why bother to reply...some people have nothing better to do.
    Yes there chep and easy to come by...Ive already got a new one.
    All I wanted was to make a diagram of whats inside the bloody thing...it was a simple question and required a simple answer.
    NO NEED TO A WANKA !!
    I feel a bann comming up.
    Have you tryed Google ? really.. your question is inrelevant. No need to reply indeed.
    Why do you come here asking this question anyway ? is it becouse you have a MSI gfx card ? and the adapter has nothing to do with this ?
    You think you can come in here yelling.. thinking we have to put up with it and accept your style of posting. This is not a MSI tech center.. it's a user to user center.. Your question has nothing to do with MSI relavant things anyway's.
    Google = your friend.
    Quote from: BOBHIGH on 17-December-05, 09:21:31
    it was a simple question and required a simple answer
    Simple for who ? you (buying a new one) ? me ? we ?   .really...........
    Quote from: Dynamike on 16-December-05, 04:11:48
    1: There are allot of diffrent types of those adapters.
    If any of the mods have a problem about my reply.. please pm me.

Maybe you are looking for