This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes ServerSocket question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "ServerSocket question " Watch "ServerSocket question " New topic
Author

ServerSocket question

Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 639
Hi all
i've set the ServerSocket constructor to accept 1 connection i.e ( ServerSocket socket = new ServerSocket(5000,1);
However if the server socket has already accepted a connection and another client socket tries to connect to it , it sucessfully makes a connection to the ServerScocket though the ServerSocket does not accept it (The client socket does not even throw an exception) . How can i prevent the client socket from making a connection to the serversocket if the serversocket has already accepted a connection ?
Thanks in advance


Raghav.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 639
Any inputs ?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
You're not setting the maximum # of connections accepted -- you're setting the length of the queue of clients waiting to be accepted. If the queue is full, the connection is rejected.
Not sure if a queue size 0 would actually work.
- Peter
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 639
Originally posted by Peter den Haan:
You're not setting the maximum # of connections accepted -- you're setting the length of the queue of clients waiting to be accepted. If the queue is full, the connection is rejected.
Not sure if a queue size 0 would actually work.
- Peter

I,am not using a while loop that means i,am allowing only one conection at one time . Secondly i've specified the que length as 1.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
And your second client is patiently sitting in your 1-deep queue, waiting for its turn to be served.
- Peter
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 639
Thats the point . Why should my second client who connects to the server wait when the server is accepting just one connection and secondly it is not even accepting connections in a while loop.
Should not the second client who connects to this server throw a connection refused sort of Exception.
Originally posted by Peter den Haan:
And your second client is patiently sitting in your 1-deep queue, waiting for its turn to be served.
- Peter
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Did you try a 0 queue depth? As I said, I'm not sure if it's legal or not, but worth a try.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServerSocket question
 
Similar Threads
Java NIO socket communication: why can I still send data after the server closed the connection?
get client's IP adress without servlets or jsp?
help me to solve this error
ServerSocket crash with Thread
Sending data from client to Server