network programming question - multiple clients

Discussion in 'Java' started by Q X, Sep 22, 2003.

  1. Q X

    Q X Guest

    Hello everyone,

    I have a problem with a client/server application where it works just
    fine with 1 client, but when I try to connect to the server with
    another client - it hangs.

    This is what a client does when it tries to connect to the server:
    //connects to the server
    myClient = new Socket(InetAddress.getByName(myServer), 1234);
    //create the streams for sending and receiving data
    out = new ObjectOutputStream(myClient.getOutputStream());
    out.flush();
    //the next line HANGS!!!!
    in = new ObjectInputStream(myClient.getInputStream());

    It hangs with the 2nd client (didn't happen with the 1st) in the last
    line of code above when it tries to get the input stream.

    Does anyone know the reason for this?

    Help is much appreciated.
    Q X, Sep 22, 2003
    #1
    1. Advertising

  2. On 21 Sep 2003 19:17:31 -0700, Q X wrote:
    > This is what a client does when it tries to connect to the server:
    >
    > //connects to the server
    > myClient = new Socket(InetAddress.getByName(myServer), 1234);


    > //create the streams for sending and receiving data
    > out = new ObjectOutputStream(myClient.getOutputStream());
    > out.flush();


    > //the next line HANGS!!!!
    > in = new ObjectInputStream(myClient.getInputStream());
    >
    > It hangs with the 2nd client (didn't happen with the 1st) in the
    > last line of code above when it tries to get the input stream.


    When you create an ObjectInputStream, it waits until the other end
    creates the corresponding ObjectOutputStream. That's where your
    problem is, but you've only shown half of the relevant code. What does
    *other* end of the connection look like?

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Sep 22, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew E
    Replies:
    1
    Views:
    340
  2. Francesco
    Replies:
    1
    Views:
    514
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Dec 27, 2006
  3. Replies:
    1
    Views:
    1,198
  4. Frank Millman
    Replies:
    8
    Views:
    380
    Frank Millman
    Jul 23, 2007
  5. Todd M. Taylor

    Multiple Roles with Multiple Clients

    Todd M. Taylor, Mar 25, 2005, in forum: ASP .Net Security
    Replies:
    0
    Views:
    144
    Todd M. Taylor
    Mar 25, 2005
Loading...

Share This Page