Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

perl client for

by argosback (Initiate)
on Nov 27, 2013 at 17:19 UTC ( #1064657=perlquestion: print w/replies, xml ) Need Help??
argosback has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm trying to get information or examples to make a client for (Node.js) from a perl script, I was searching in Google but I don't find anything. Thanks

Replies are listed 'Best First'.
Re: perl client for
by zentara (Archbishop) on Nov 30, 2013 at 17:03 UTC
    The old way to do a bi-directional socket, and usually the most foolproof, is to use a forking model. One fork watches for input fron STDIN to send, and the other fork receives from the socket. Try it.
    #!/usr/bin/perl -w use strict; use IO::Socket; my ( $host, $port, $kidpid, $handle, $line ); #unless ( @ARGV == 2 ) { die "usage: $0 host port" } ( $host, $port ) = @ARGV || ('localhost',4444); # create a tcp connection to the specified host and port $handle = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => $port ) or die "can't connect to port $port on $host: $!"; $handle->autoflush(1); # so output gets there right away print STDERR "[Connected to $host:$port]\n"; # split the program into two processes, identical twins die "can't fork: $!" unless defined( $kidpid = fork() ); # the if{} block runs only in the parent process if ($kidpid) { # copy the socket to standard output while ( defined( $line = <$handle> ) ) { print STDOUT $line; } kill( "TERM", $kidpid ); # send SIGTERM to child } # the else{} block runs only in the child process else { # copy standard input to the socket while ( defined( $line = <STDIN> ) ) { print $handle $line; } }
      The OP's question is unfortunately not about sockets, but instead about a poorly-named Javascript library.
        Hi, I'm just getting into the javascript and node.js end of things. My preliminary understanding is that node.js is a server ( basically a socket) that communicates with javascript running in the browser. So theoretically, shouldn't you be able to communicate directly with node.js thru a socket program, assuming you send the right data to node.js. Just as though you can communicate with a standard web server with a socket program, as arduous as it may be.

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh

      I'd like to try this for a project I'm working on. However, I'm not clear about using it.

      That is to say, I'm not sure how to invoke it. How do I invoke the script and have it stay running to exchange form updates between the script on the server, and the web page on the client?

      Once invoked, how do you shut it down once that page is done with it?

      I'm not new to Perl, but I am new to Sockets of any kind. I have a project with a page that holds scheduling information and it needs to be accessible/updateable by more than one user at a time.

      Even if you can just point me to a good resource that explains the above, I'm happy to do the legwork. I just haven't read anything yet that answers those questions. Even the popular doesn't do much to explain that part of it. It only gives examples of a pseudo-server running from the client, not from a web server.

      Thank you for your time.

Re: perl client for
by argosback (Initiate) on Nov 27, 2013 at 17:57 UTC
    Hi, I make a client with the info that I found, but when I send a emit I get this from
    debug - client authorized info - handshake authorized qs3kbEVnsoRBhD9hq91S debug - destroying upgrade
    My code is:
    #!/usr/bin/perl -w use PocketIO::Client::IO; my $socket = PocketIO::Client::IO->connect("http://localhost:1506"); my $cv = AnyEvent->condvar; my $w = AnyEvent->timer( after => 5, cb => $cv ); $socket->on( 'message', sub { say $_[1]; } ); $socket->on( 'connect', sub { $socket->send('Parumon!'); $socket->emit( 'message', { name => 'name', message => 'msg emit' +} ); print "connected"; } ); $cv->wait;
      Hi , I tried the code above .The problem I get after trying to connect to my node js server is this : 28 {"code":0,"message":"Transport unknown"} 0 at /usr/local/share/perl5/AnyEvent/PocketIO/ line 86. Can't call method "transport" on an undefined value at line 9.

        As your $socket object is undefined, it means the connect did not work all right.

        You may debug it by inspecting the port or at least check if PocketIO::Client::IO->connect succeeded (i.e. returned an object).

        Cheers, Sören

        Créateur des bugs mobiles - let loose once, run everywhere.
        (hooked on the Perl Programming language)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1064657]
Approved by marto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2018-07-19 18:00 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (414 votes). Check out past polls.