Ultra-simple TCP Socket Server

Sometimes you just want to know that a connection is being made:

perl -MIO::Socket::INET -e '
  $s = IO::Socket::INET->new( Listen => 5, LocalAddr => 'localhost', LocalPort => 12345, Proto => 'tcp' );
  while ( push @c, $s->accept() ) { print "got connect\n"; }

Pushing onto @c keeps the connection alive (otherwise it is closed when it goes out of scope). Nothing whatsoever is done with the connection. This can be useful for doing tests like checking if a connection is being made, or checking what happens when a connection can be made but the server then fails to respond (checking post-connection timeout conditions).

To test the actual connection the result of $s->accept() could be used (ie using send/recv).

BradsWiki: Programming Notes/PerlProgramming/UltraSimpleTCPSocketServer (last edited 2012-04-16 13:36:28 by BradleyDean)