Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Multiple connections between same client-server

843790Jul 21 2010 — edited Aug 26 2010
Hello,
I have a code already implemented which acts as a Client asking for connection on the port 2001. This code is not mine so i can't see nor change it.
Now i have written the server side, in which i open the port 2001 to wait for this client. This is my code:

ServerSocket servSock = new ServerSocket(2001);
servSock.setSoTimeout(30000);
Socket clntSock = new Socket();
System.out.println("Waiting for a client...........2001");
clntSock = servSock.accept();
clntSock.setSoTimeout(3000);

When i run the application, the port is opened, the client ask for connection, i accept it with the clntSock = servSock.accept(); and the rest of the program runs correctly. But sometimes, after this process, and once the connection has been established, the client still asking me for a new connection, so with a TCPVIEW program i can see that there are a lot of connections established between my server and the client and it makes the client program to stall.
I have readen that when you open the serversocket (new ServerSocket(2001);), and a client ask for connection, the connection is established but you only can manage it after you accept it with the servSock.accept(); sentence.

I think is possible that the client is not well implemented and sometines it doesn't realize that the connection with the server has been established and it still sending me connection request. Or perhaps it is my error because i am not mannaging this correctly.
However, i cannot change the code of the client so i have to do something with my server code to handle this situation.

If anyone has some idea about that, i am glad to read it because i am working on it for a long time and i cannot find a good solution.

Thanks in advance!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 23 2010
Added on Jul 21 2010
13 comments
457 views