Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing a command for a specified time

Status
Not open for further replies.

streakz

Programmer
Nov 21, 2004
3
US
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.

 
Streakz,

I think you have that the wrong way around.

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.
 
alarms = non-portable, endless fiddling to get (1/2 way) right etc...

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top