Waiting for ServerSocket accept() to put socket into "listen" mode
Posted
by
inazaruk
on Stack Overflow
See other posts from Stack Overflow
or by inazaruk
Published on 2010-12-29T10:44:31Z
Indexed on
2010/12/29
10:54 UTC
Read the original article
Hit count: 158
I need a simple client-server communication in order to implement unit-test.
My steps:
- Create server thread
- Wait for server thread to put server socket into listen mode ( serverSocket.accept() )
- Create client
- Make some request, verify responses
Basically, I have a problem with step #2. I can't find a way to signal me when server socket is put to "listen" state. An asynchronous call to "accept" will do in this case, but java doesn't support this (it seems to support only asynchronous channels and those are incompatible with "accept()" method according to documentation).
Of cause I can put a simple "sleep", but that is not really a solution for production code.
So, to summarize, I need to detect when ServerSocket has been put into listen mode without using sleeps and/or polling.
© Stack Overflow or respective owner