This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to implment server socket reject?  RSS feed

 
Chinn Xu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I need to do:
Server controls limit number of socket connections
at one time. If available, client can connect, if
server connections beyond the limit, new client is
rejected IMMEDIATELY with specific exception message. When server connections are available again, new client's request will be handled as normal.
From java.net package, I did not find any API
so far, any socket expert's advises?
Thx!
 
Nayanjyoti Talukdar
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think u can put a counter in Server program. Everytime, client connects to the server, the counter will be incremented. As soon as it reaches the configured value, pass the message to the client saying No more connections available.
This will be one solution since as u said, there is no API.
Regards
Nayan.
 
Chinn Xu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the response.
The 2 major drawbacks are:
1. Client has to be blocked at socket
input stream to read something from
server every time.
2. If there are tens of or hundreds of
concurrent users making requests and
no available seats, then the server has
send tens of hundreds short messages to
notify the clients.
I am wondering why socket API does not have
reject(Object obj) method like, since it has
accept method. It does not make sense.
Maybe, all underlying OS network C interface
does not support "reject" historically.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!