• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get number of pending requests or accept requests without blocking in ServerSocket?

 
Volodymyr Lysenko
Ranch Hand
Posts: 512
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created subclass of `java.net.ServerSocket`.

In `run` method I want to get all pending requests and send them error message.

How to do it with `ServerSocket`?

Here is my code:

I need either number of pending requests or non-blocking variant of `accept`?
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically what you do to process more than one request from a SocketServer at the same time is this: for each Socket returned by the accept() method, create a new Thread to process the input received from that Socket.

I don't understand why allowing accept() to block if there are no pending requests is a problem, since your goal seems to be to deal with pending requests.
 
Henry Wong
author
Sheriff
Posts: 22516
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As a side note, I do not believe that the "number of pending connections" are exposed by TCP (the protocol and/or the socket API), so the Java classes written for them can't expose it either.

You can, however, specify the maximum number of pending connections... but even with that, it is only a "suggestion". The implementation may choose to ignore it.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!