millionth socket problem....



hi there...

Still trying to understand perl-socket-programing, I copyied a short
skript from the perl cookbook. To test it, I checked it with telnet, so
my client *is* working.

My server is the following, and ... it doesn't work (at least not as
expected):

*****************************
#!/usr/bin/perl

use POSIX qw(:sys_wait_h);
use Socket;

# make the socket
socket(SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
# so we can restart our server quickly
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1);
# build up my socket address
$my_addr = sockaddr_in('23', INADDR_ANY);
bind(SERVER, $my_addr) or die "Couldn't bind to port 23 : $!\n";
# establish a queue for incoming connections
listen(SERVER, SOMAXCONN) or die "Couldn't listen on port $server_port
: $!\n";

sub REAPER {
1 until (-1 == waitpid(-1, WNOHANG));
$SIG{CHLD} = \&REAPER; # unless $] >= 5.002
}

$|=1;
$SIG{CHLD} = \&REAPER;
print 'setting up server'."\n";
while ($hisaddr = accept(CLIENT, SERVER)) {
print CLIENT "\n\r*** both talking ***\n\r";
print 'forking'."\n";
my $CPID=0;
next if $CPID = fork; # parent
print CLIENT "\n\r*** child talking ***\n\r";
die 'fork: '."$!" unless defined $CPID; # failure
# otherwise child
close(SERVER); # no use to child
$|=1;
print 'client got'."\n";
print CLIENT "\n\r*** hi & good bye! ***\n\r";
print '\n*** closing client ***'."\n";
exit; # child leaves
} continue {
print CLIENT "\n\r*** parent talking ***\n\t";
print 'parent closing client...';
close(CLIENT); # no use to parent
print '...parent done!'."\n";
}


*****************************


when im telnetting to it, it returns

*** both talking *** (just once, expected was twice)

and

*** parent talking ***

as expected, and the server itself prints 'client got' and all the
other stuff i wanted it to print.
but the 'child talking' and 'Hi & goodbye!' dont go to the client.
So my question is: what am i doing wrong? As far as I can see,
-> print CLIENT "\n\r*** parent talking ***\n\t"; <-
works well for the parent but not for the child.
Any help welcome ;-)

.



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: SBS 2003 SP 1 on MSDN disks
    ... the PPPoE client, which I believe it operate as, even if Earthlink does not know it, and stop using the Windows Server 2003 PPPoE client to connect. ... I have started the Telnet service on my client computer ... I have started the Telnet service on the SBS2003 server. ...
    (microsoft.public.windows.server.sbs)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
    (microsoft.public.vc.language)
  • Re: TCP server stop receiving new connections
    ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
    (microsoft.public.win32.programmer.networks)