js1 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings noble monks of perl!

I am trying to get to the bottom of a problem on a server we use at work. It's not a web server though, it's an access server called by an apache plugin when people log in to a protected website.

What happens is that the access server appears to be running, but stops listening (it should listen on port 6021). It's been suggested that this might be due to too many connections. Therefore in order to test this I wanted to come up with a perl script. I'm not asking any monks to write this for me, but could someone enlighten me, or suggest a code snippet that might test this please?

I bow before thy great wisdom!

js1.

Replies are listed 'Best First'.
Re: running but not listening
by ghenry (Vicar) on May 15, 2005 at 14:46 UTC

    Hi,

    My first thought would be to create a program that connects to your server via a telnet connect (on port 6021), which forks for each connection. When it can no longer get a connection, you have hit it's limit.

    The server might drop the connection after a finite amount of time if it does not receive any data, so bear this in mind.

    I may well be totally of track with this idea though.

    Is there any info on some kind of limit in the servers documentation? What about the servers memory?

    TIMTOWTDI.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!
Re: running but not listening
by ambrus (Abbot) on May 15, 2005 at 15:53 UTC

    Just a few suggestions.

    You could try using to list the listening sockets. However, you need some extra options because by default, netstat may list only connected sockets. On linux, try netstat -paAinet, on solaris, netstat -afinet.

    Also, you may just need a program like netcat or nmap.

Re: running but not listening
by northwind (Hermit) on May 15, 2005 at 16:43 UTC

    Considering what you are running, I doubt what I am about to propose is the answer.  Now with the caveat out of the way... at any point in the telephone game you're playing (user => web page => your script => apache => access) would blocking I/O be a factor?  For IPC, I know this is an issue; not sure about sockets though.

Re: running but not listening
by zentara (Cardinal) on May 16, 2005 at 07:41 UTC
    Here is a simple pure socket script to test a port, change the port to 6021, and the @pages to suit your needs.
    #!/usr/bin/perl # Very simple client program to search for # regular expressions on specified Web sites. # require 5.002; use strict; use Socket; # Perl 5 technique for declaring local variables. my ( $host, $in_addr, $proto, $port, $addr ); my ( $response, $page, $file, $pattern, %urls ); # Set up some URLs and patterns in an array hash my @pages = ( "zentara.net", "perlmonks.org" ); foreach $page (@pages) { ( $host, $file ) = split /\//, $page, 2; # Form the HTTP server address from the host # name and port number $in_addr = ( gethostbyname($host) )[4]; $port = 80; $addr = sockaddr_in( $port, $in_addr ); $proto = getprotobyname('tcp'); # Create an Internet protocol socket. socket( S, AF_INET, SOCK_STREAM, $proto ) or die "socket:$!"; # Connect our socket to the server socket. connect( S, $addr ) or die "connect:$!"; # For fflush on socket file handle after every # write. select(S); $| = 1; select(STDOUT); # Send get request to server. print S "GET /$file HTTP/1.0\n\n"; print "===================$page===========================\n"; # Look for patterns in returned HTML. while (<S>) { foreach $page (@pages) { print; } } close(S); } exit;

    I'm not really a human, but I play one on earth. flash japh
Re: running but not listening
by thcsoft (Monk) on May 16, 2005 at 01:05 UTC
    if you check the documentation for IO::Socket::INET, you'll find an argument to the constructor specifying the queue size for a listening socket. this is the second argument to the listen call, see man 2 listen.
    possibly you'll have less work to do if you try play with this value first.

    language is a virus from outer space.