Win a copy of Head First Android this week in the Android forum!
  • 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

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

 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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`?
 
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic