network programming question - multiple clients

Q

Q X

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.
 
G

Gordon Beaton

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top