• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

ServerSocket question

 
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any inputs ?
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And your second client is patiently sitting in your 1-deep queue, waiting for its turn to be served.
- Peter
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic