testing tcp connection

------_=_NextPart_001_01CB499F.388FA81A
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

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 =3D IO::Socket::INET->new(Proto=3D>"tcp", LocalPort=3D>$port,
Listen=3D>$maxconn, Reuse=3D>1, Timeout=3D>300)

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



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

$clientip =3D $client->peerhost();

$clienthost =3D 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 <http://www.springeronline.com>
www.springer.com <http://www.springer.com/>

-






------_=_NextPart_001_01CB499F.388FA81A--
Marco.vanKammen [ Mi, 01 September 2010 08:30 ] [ ID #2046995 ]

AW: testing tcp connection

Kammen van, Marco, Springer SBM NL <Marco.vanKammen [at] springer.com> 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-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
t.baetzler [ Mi, 01 September 2010 08:57 ] [ ID #2046996 ]

RE: testing tcp connection

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

>>Kammen van, Marco, Springer SBM NL <Marco.vanKammen [at] springer.com> =
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-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Marco.vanKammen [ Mi, 01 September 2010 09:29 ] [ ID #2046997 ]
Perl » gmane.comp.lang.perl.beginners » testing tcp connection

Vorheriges Thema: Question on Unless and Until
Nächstes Thema: How to test Output when using IPC::Open3