Results 1 to 7 of 7
  1. #1
    senca is offline Member
    Join Date
    Feb 2010
    Posts
    36
    Rep Power
    0

    Default logical accept() method issue

    Hey everyone,

    I've got a probably stupid problem thats been bugging me. I have a server and a client class that can connect with sockets.
    As long as its used in eclipse it works as a charm because you can run the java files separataly. But I need to export it into a jar file and that gives me headaches.
    The server has the method accept() that waits on a connection by the client. But the code stops at the accept until there is a connection. How is the client ever going to connect if the code stops at accept() ?

    I absolutelly see no solution to this. In eclipse you just run the server that will stop and wait when calling the accept() method and you can then click on the client to make the connection. But the client needs to auto connect one way or another when its put in a jar.

    I've been working my code in a lot of ways but still nothing. Making a global class where the 2 classes 'meet' isn't really helpfull since again calling accept() stops the whole process.
    Synchronizing also hase the same problem, first you need to accept before you can connect but if you accept, this method will hold until connected.

    Does anyone have a clue on what to do with this kind off problem?

    Greetz

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: logical accept() method issue

    But the code stops at the accept until there is a connection. How is the client ever going to connect if the code stops at accept()
    It is supposed to wait until a client connects - read the API for the accept method. It sounds like your client and server are in the same programmatic flow (which means for one thing using a Client and Server is not necessary) - you provide not code to verify if this is the case, and without code as an SSCCE we guess, and guesses can often times be incorrect. If somehow I managed to guess correctly, the client must be in a separate Thread than that of the server.

  3. #3
    senca is offline Member
    Join Date
    Feb 2010
    Posts
    36
    Rep Power
    0

    Default Re: logical accept() method issue

    I took this one as an example:
    Java Socket Programming Example

    This works under eclipse but as you can see it gives trouble when using them in the commandline.
    This should be the base of a proxy server with this client/server classes as the proxy.

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: logical accept() method issue

    So, do they both reside in different jar's? Do you starting the server first, then starting the client?

  5. #5
    senca is offline Member
    Join Date
    Feb 2010
    Posts
    36
    Rep Power
    0

    Default Re: logical accept() method issue

    I didn't try this in jar's yet because of the 2 mains. Also in eclipse you can start them manually but in the commandline it should be done with a single command that will make them both running.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: logical accept() method issue

    If you have both the server and the client running in the same JVM you're running into troubles of course. Run both in separate JVMs and see what happens. The server should block until a socket was accepted and the client should block until its socket was accepted by a server.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: logical accept() method issue

    You need 2 threads - either 2 different JVM instances (eg you run them separately) or 2 threads within the application itself.

Similar Threads

  1. Bubblesort Issue within Method
    By burrish in forum New To Java
    Replies: 9
    Last Post: 09-27-2011, 02:39 AM
  2. Logical inheritance issue...
    By senca in forum New To Java
    Replies: 2
    Last Post: 06-14-2011, 11:00 AM
  3. Issue in method anonymous class in GWT
    By ankit01 in forum GWT
    Replies: 0
    Last Post: 05-16-2011, 11:25 AM
  4. ServerSocket.accept() using 100%+ CPU
    By pagod in forum Networking
    Replies: 2
    Last Post: 05-28-2010, 09:42 AM
  5. Accept 2 values ....
    By danny000 in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 02:12 PM

Posting Permissions

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