Perl socket timeout

M

mdemmitt

Hi,
I am new to perl socket programming. I have written a simple perl
server. I call:
$client = $server->accept()

I want the $client socket to timeout and automatically close after 15
seconds. Is this possible. I've googled for this, but can't find
anything specific to my question. Anyone have experience with this.

-Mike
 
S

Sébastien Cottalorda

(e-mail address removed) a écrit :
Hi,
I am new to perl socket programming. I have written a simple perl
server. I call:
$client = $server->accept()

I want the $client socket to timeout and automatically close after 15
seconds. Is this possible. I've googled for this, but can't find
anything specific to my question. Anyone have experience with this.

-Mike
Hi,

perldoc -f alarm

Hope this helps.

Sebastien
 
X

xhoster

Hi,
I am new to perl socket programming. I have written a simple perl
server. I call:
$client = $server->accept()

I want the $client socket to timeout and automatically close after 15
seconds.

From what you have shown, you are not doing anything with the $client
connection, so there is nothing to time out. Is it really the accept
call (on the $server socket) which you wish to timeout?
Is this possible. I've googled for this, but can't find
anything specific to my question. Anyone have experience with this.

There is more than one way to do it, and the best way depends on what
you want to do after timing out. You could use "alarm", or you could
use IO::Select. (If canread returns the $server socket, then you know you
can call accept on it without blocking.)

Xho
 
M

mdemmitt

From what you have shown, you are not doing anything with the $client
connection, so there is nothing to time out. Is it really the accept
call (on the $server socket) which you wish to timeout?

The code above is not all of the code. The line above is used to
accept an incoming connection. Afterwards, I read from and write to
$client. Eventually, when the client wants the server to close the
connection it sends a specific token, let's say the token is "END". I
want to account for the possibility of the client machine crashing or
failing to send END. To account for these possibilities, I want $client
to automatically close 15 seconds after it has been opened. Is this
possible? I will look into alarm and see if there is a way I can use
that to replicate the functionality I am looking for. It would be
nice, however, to be able to set some timeout value for a client
socket.

Thanks,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top