Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Re: Activeperl 5.6 fork() doesn't friggin work

by Anonymous Monk
on Apr 18, 2002 at 01:12 UTC ( #160069=note: print w/replies, xml ) Need Help??

in reply to Re: Activeperl 5.6 fork() doesn't friggin work
in thread Activeperl 5.6 fork() doesn't friggin work

This code does work, but it's assuming the client has to write to the server, and then the server replies. While this is generally the case, it's ALSO possible for the server to write to the client without first receiving any information. For example, the client could send the server "data:foo", then the server responds "received". If that was all the information the server needed to complete the operation, it would then respond saying whether the task completed successfully or not. The reason I was forking is so that I have a persistant child listening for whatever the server said.
  • Comment on Re: Re: Activeperl 5.6 fork() doesn't friggin work

Replies are listed 'Best First'.
Re: Re: Re: Activeperl 5.6 fork() doesn't friggin work
by premchai21 (Curate) on Apr 18, 2002 at 01:47 UTC

    Ah. I gathered from your original post (assuming you are jtx) that it was always client, server in strict alternation. If that's not the case, you might be able to use select to determine whether there is data waiting to be read. I believe POE can do this sort of stuff relatively easily, though it may well be overkill.

      What I have been able to do, though it is a cheap hack and will probably have to be re-written if I want this to be a serious program, is taken your idea of using a while loop and somewhat modifying the server/client. This is the modified client, and it works, though like I said, I think it's pretty cheesy:
      #!/usr/bin/perl use IO::Socket; # Make our connections my $ns1 = new IO::Socket::INET (PeerAddr => 'ns1', PeerPort => 1200, Proto => 'tcp' ) or die "Couldn't create socket: $!\n" +; my $line; my $count = 0; my $domain = ''; my $ipaddress = ''; while ($line ne 'CAIO') { if ($count == 0) { print $ns1 "HELO\n"; $count++; } elsif ($count == 1) { print $ns1 "dom:$domain\n"; $count++; } elsif ($count == 2) { print $ns1 "ipaddr:$ipaddress\n"; $count++; } elsif ($count == 3) { print $ns1 "addzone\n"; $count++; } sleep(1); chomp($line = <$ns1>); print "$line\n"; } close($ns1);
      As you might have gathered, the server is a name server, and this program was created to add zones via sockets. It's irrelevant to me at this point whether or not BIND supports this natively - This is just a good way for me to practice using Sockets and TK, and make my boss happy while I write programs that will eventually end up being my replacement :)


        my (@cmds) = ("HELO", "dom:$domain", "ipaddr:$ipaddress", "addzone"); while (@cmds) { print $ns1 shift(@cmds), "\n"; $line = <$ns1>; # don't need the sleep; # the read should block until # a line is available. defined($line) or last; # quit if connection closed # (could die instead) print $line; # don't need \n now, $line # not chomped ($line =~ /^CAIO$/) and last; # $ can handle trailing # newline, with no # significant speed penalty # (should be optimized by # regex engine) }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://160069]
[1nickt]: This is less than perfect ... but demanding perfection (from people or from life) is a sure way to unhappiness.
[Discipulus]: and anyway we have CB where every (democratic) opinion can be expressed
erix eat the rich!
[1nickt]: I do think it is sad that roho has received 3 downvotes for his polite request, as did I when I objected to the profanity in stonecolddevin's sig. I upvoted both him and Karl for the discussion. Way too much downvoting for inappropriate reasons here!
Discipulus learn that 'argue' has a little negative sense, he thought was a neutral sense, 'vox media'
[1nickt]: argue == discuss && argue == be contentious
[Discipulus]: you are right 1nickt i didnt voted nor downvoted; I just upvote perl content i like
[1nickt]: In Spanish, to argue (like a fight) is discutir -- does not mean to discuss !
[1nickt]: Sigh, this is why I gave up human-only languages and became a Perl linguist :-)
[Discipulus]: i just, rarely, downvote unpolite posts and spam, and wrong advices

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2017-06-22 12:21 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (519 votes). Check out past polls.