$Bill Luebkert <> wrote:
> Barry Brevik wrote:
> 
>> I've created a server application that listens on a port. It works
>> great. While it is running, it prints diagnostic messages to the
>> screen. It seems that as soon as the app does an accept():  
>> 
>>   $client_addr = accept(CLIENT, SERVER);
>> 
>> ...for example, print() statements to STDOUT do not show on the
>> screen until the app terminates. 
>> 
>> I discovered that if I do:
>> 
>>   print STDERR "my message\n";
>> 
>> ...I get the result I am looking for.
>> 
>> My question is: I just want to understand this. Why do I have to
>> write to STDERR after opening a socket? Is it maybe a bad idea to do
>> this??  
> 
> Try unbuffering your I/O to STDOUT.  $| = 1;  (make sure STDOUT is
> selected at the time - it's the default if you haven't done a select
> yet)  

Perhaps, but that hasn't been a problem in my experience of socket i/o.
There may of course be some other reason. If Barry could provide a
small, self contained script that demonstrates the problem it might be a
lot easier to see. For example, the following simple server script
doesn't have the problem described, at least when I run it.

---------------------------------------------
use strict;
use warnings;
use IO::Socket::INET;

my $l = IO::Socket::INET->new(LocalPort => 9876,
                              Listen => 1,
                              ReuseAddr => 1);
defined $l or die "Failed to create listener: $!\n";
print "Listening\n";
while (my $s = $l->accept) {
    my $peer = $s->peerhost;
    print "Accepted connection from $peer\n";
    while (<$s>) {
        chomp;
        print "Received: $_\n";
    }
    close $s;
    print "Socket closed - listening again\n";
}
---------------------------------------------

HTH

-- 
Brian Raven 


=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the 
intended addressee(s). Unauthorised reproduction, disclosure, modification, 
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message do not 
necessarily reflect those of Atos Euronext Market Solutions.

L'information contenue dans cet e-mail est confidentielle et uniquement 
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. 
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail 
vous parvient par erreur, nous vous prions de bien vouloir prevenir 
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre 
systeme. Le contenu de ce message electronique ne represente pas necessairement 
la position ou le point de vue d'Atos Euronext Market Solutions.

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to