How can I listen to a port for a N seconds? For example, on the server: $MySocket->recv($text, 128) waits for a message from the client. I want the server to wait for 5 seconds and if no response, then stop.
According to IO::Socket, you can set a timeout using timeout([VAL]). Not sure if the timeout is in seconds or milliseconds though... but give it a try.
Instead of listening for five seconds I think you should do what it says in the documentation: Use non-blocking I/O and, wait for a couple of seconds and then try again.
Mike
To err is human,
but to really foul things up -
you require a man Mike.
Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884
if you "wait a couple of seconds" (sleep?), your server response time will be (as seen by the clients) noticeably reduced.
a true "server" should be able to respond to multiple clients.
Select, using the timeout option is the most flexible
alarm/listen/SIGALRM will probably work. My listen() man page does not say anything about EINTR. AFIK, an alarm() will cause an EINTR on a listen() when it expires.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.