This seems to work:

use warnings; use strict; use IO::Socket; my $socket = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => '8888', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $socket; $|++; while (1) { my $incoming = $socket->accept(); while(<$incoming>) { print $_; } print "\nNext session.\n"; } close($socket);

Here is how I run it as a daemon in Unix:

$ nohup ./listen.pl >listen.log 2>listen.log &

After it is running, here I am testing it out:

$ telnet localhost 8888 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. You there? ^] telnet> quit Connection closed.

And here is the output showing up in my log:

$ cat listen.log You there? Next session.

And here is the process still running afterwards.

$ jobs [1]+ Running nohup ./listen.pl > listen.log 2> listen.log &

In reply to Re: Background Run by Anonymous Monk
in thread Background Run by avatarengineer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.