I wrote something for your, hope it helps:
server.pl: use IO::Socket; use strict; $| ++; my $server = new IO::Socket::INET(Timeout => 7200, Proto => "tcp", LocalPort => 3000, Reuse => 1, Listen => 2); my $num_of_client = -1; while (1) { my $client; do { $client = $server->accept; } until (defined($client)); print "accepted a clinet, id = ", ++ $num_of_client, "\n"; if (!fork) { close($server);#this only closes the copy in the child process while (1) { my $msg; $client->recv($msg, 1000); if ($msg eq "") { die "child $num_of_client is inactive\n"; } else { print "rcvd $msg from client ", $num_of_client, "\n"; sleep(2); print $client $msg; } } } else { close($client); #this only closes the copy in the parent proce +ss, assume the parent no longer need talk to the client } } clinet.pl: use IO::Socket; use strict; my $server = new IO::Socket::INET(Proto => "tcp", PeerAddr => "localhost", PeerPort => 3000, Reuse => 1, Timeout => 7200) || die "failed to connect to server\n"; while (1) { print $server "abcd"; my $msg; $server->recv($msg, 1000); if ($msg eq "") { die "server is not responding"; } else { print "recv'd ", $msg, "\n"; } }

In reply to Re: Socket question Help! by pg
in thread Socket question Help! by drake50

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.