Re: millionth socket problem....




..rhavin grobert wrote:
> 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 ;-)

Your program worked for me, if I changed the port number to 7023, as
ports below 1024 are reserved by the system, and I telnet from the same
host using 'localhost' as a host name. You should only get "***both
talking *** once, because your program sends that to the client before
forking.

.



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: Unable to print to networked printer - get access denied messa
    ... Check the permissions on the server assuming the client has a true RPC ... How is the Standard TCP/IP port configured for the device? ...
    (microsoft.public.windowsxp.print_fax)
  • Re: interfaces lo:1 lo:2 lo:3? (for remote ssh tunnels)
    ... That's the problem tunneling (port forwarding) solves. ... >>can't get past the client firewall. ... > I don't understand why the server would be making the ... server initiates another connection to the client -- in this ...
    (Debian-User)
  • RE: call is blocked in recvfrom() and no further proceedings in Win CE
    ... In windows CE, I'm able to send a request but I'm unable to receive it. ... Create another socket & bind with server IP address. ... > My program has to send request to service through port 5070(in this port only ...
    (microsoft.public.windowsce.embedded)
  • Re: Remote Connection Issue
    ... through port number 3389 and a workstation on the LAN through port number ... I understand that you want to allow a LAN client ... and you have configured server publishing rule ... > By default Terminal Server and Windows 2000 Terminal Services uses TCP ...
    (microsoft.public.windows.server.sbs)