I try to write a client server application based on Net::Server::PreFork. The communications are going through but the problem is that both the client and the server waits for new line \n before they process the input.
Note that this is bidirectional - client send something to server, and then waits for answer on the same socket.

I expect to have large amounts of data going forth and back between the server and the clients. The data may contain new lines so it mess my logic.
I also expect many many connections so I think it's best to keep going with the PreFork.

Here is the server code and the client code. Please help me find what am I doing wrong.
Any suggestion is welcome... Thanks!

Server

#!/usr/bin/perl -w -T package MyPackage; use strict; use base qw(Net::Server::PreFork); MyPackage->run({port => 20205, no_client_stdout => 1}); sub process_request { my $self = shift; eval { local $SIG{'ALRM'} = sub { die "Timed Out!\n" }; my $timeout = 5; my $sock = $self->{server}->{client}; $sock->autoflush(1); $|=1; while (defined (my $buf = <$sock>)) { $buf =~ s/\r?\n$//; #sleep(5); print $sock "client said '$buf'\r\n"; alarm($timeout); $sock->close(); } alarm(0); }; if ($@ =~ /timed out/i) { print STDOUT "Timed Out.\r\n"; return; } } 1;

Client

#!/usr/bin/perl -w use IO::Socket::INET; my $sock = new IO::Socket::INET (Blocking => 1, PeerAddr => 'localhost +', PeerPort => '20205', Proto => 'tcp'); my $clean_content = ""; die "Could not create socket: $!\n" unless $sock; $sock->autoflush(1); $|=1; $sock->send("message to server\r\n"); while (<$sock>) { print $_; } close $sock;

In reply to Net::Server::PreFork requires new line to end input by yoop

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.