RE: testing tcp connection

2010-09-01 Thread Kammen van, Marco, Springer SBM NL
-Original Message-
From: Thomas Bätzler [mailto:t.baetz...@bringe.com] 
Sent: Wednesday, September 01, 2010 8:57 AM
To: beginners@perl.org
Cc: Kammen van, Marco, Springer SBM NL
Subject: AW: testing tcp connection

>>Kammen van, Marco, Springer SBM NL  asked:
>> I have an issue when something goes wrong with the client that's trying
>> to connect.
>> 
>> 9 out of 10 times this works fine, but there are odd situations where
>> $clientip doesn't get filled in, which leaves me with a connection I
>> can't do anything with...
>> 
>> I tried to use close($client) to just terminate these odd connections
>> when $clientip is empty but that doesn't work..

>From my understanding of sockets (strictly limited ;-)) you'll need to call 
>$client->shutdown( $how ):

>From perlfunc:

>  shutdown SOCKET,HOW
  
>  Shuts down a socket connection in the manner indicated by HOW, which has the 
> same interpretation as in the system call of the same name.

>shutdown(SOCKET, 0);# I/we have stopped reading data
>shutdown(SOCKET, 1);# I/we have stopped writing data
>shutdown(SOCKET, 2);# I/we have stopped using this socket

>  This is useful with sockets when you want to tell the other side you're done 
> writing but not done reading, or vice versa.  It's also a more insistent 
> >form of close because it also disables the file descriptor in any forked 
> copies in other processes.


>HTH,
>Thomas

Thanks Thomas, this seems exactly the thing I'm looking for!
I'll give this a go! 

Marco.  



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




AW: testing tcp connection

2010-08-31 Thread Thomas Bätzler
Kammen van, Marco, Springer SBM NL  asked:
> I have an issue when something goes wrong with the client that's trying
> to connect.
> 
> 9 out of 10 times this works fine, but there are odd situations where
> $clientip doesn't get filled in, which leaves me with a connection I
> can't do anything with...
> 
> I tried to use close($client) to just terminate these odd connections
> when $clientip is empty but that doesn't work..

>From my understanding of sockets (strictly limited ;-)) you'll need to call 
>$client->shutdown( $how ):

>From perlfunc:

  shutdown SOCKET,HOW
  
  Shuts down a socket connection in the manner indicated by HOW, which has the 
same interpretation as in the system call of the same name.

shutdown(SOCKET, 0);# I/we have stopped reading data
shutdown(SOCKET, 1);# I/we have stopped writing data
shutdown(SOCKET, 2);# I/we have stopped using this socket

  This is useful with sockets when you want to tell the other side you're done 
writing but not done reading, or vice versa.  It's also a more insistent form 
of close because it also disables the file descriptor in any forked copies in 
other processes.


HTH,
Thomas

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




testing tcp connection

2010-08-31 Thread Kammen van, Marco, Springer SBM NL
Hi All,

 

I have an issue when something goes wrong with the client that's trying
to connect.

9 out of 10 times this works fine, but there are odd situations where
$clientip doesn't get filled in, which leaves me with a connection I
can't do anything with... 

I tried to use close($client) to just terminate these odd connections
when $clientip is empty but that doesn't work.. 

The program keeps running but these 'zombie' connections will eventually
fill up my system. 

 

Just a small snip of the program... 

 

#!/usr/bin/perl -w

 

use strict; 

use IO::Socket qw(:DEFAULT :crlf);

 

my $server = IO::Socket::INET->new(Proto=>"tcp", LocalPort=>$port,
Listen=>$maxconn, Reuse=>1, Timeout=>300)

or die "Can't setup server\n";

 

while ( $client = $server->accept()) {

$clientip = $client->peerhost();

$clienthost = gethostbyaddr($client->peeraddr,AF_INET);

   # Some other stuff

}

 

Thanks for any tips! 

 

- 

Marco van Kammen
Springer Science+Business Media
System Manager & Postmaster 

- 

van Godewijckstraat 30 | 3311 GX
Office Number: 05E21 
Dordrecht | The Netherlands 

-  

tel 

 +31(78)6576446

fax 

 +31(78)6576302

- 

www.springeronline.com   
www.springer.com  

-