Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
Ranch Hand
Posts: 514
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`?
 
Sheriff
Posts: 23640
48
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.
 
author
Sheriff
Posts: 23566
138
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!