This week's book giveaway is in the iOS forum.
We're giving away four copies of Classic Computer Science Problems in Swift and have David Kopec on-line!
See this thread for details.
Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 23503
46
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: 23484
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!