Frage

How to communicate between node.js and perl Catalyst applications?

I have two applications: Node.js and Catalyst.

Now these two applications communicate each other by HTTP. But it's not fast and secure way.

What another way to communicate its, like local unix socket or other?

What perl modules and node.js packages can i use?

War es hilfreich?

Lösung

A couple of options:

ZeroMQ - Node binding; Perl binding

dnode - perl dnode protocol support

Lots of possibilities for message transport (e.g. RabbitMQ) and network communication... but it sure would be nice to stick with HTTP (on top of SSL/TLS) for all of support that will come with it.

Andere Tipps

It's too much to write a full answer about your problem, since I haven't worked with Catalyst since a long time ago, but here you go a simple working UNIX Socket perl-server, node-client proposal

Server :

#!/usr/bin/perl -w -T

use strict;
use IO::Socket::UNIX;
use threads;

my $socket_path = "/tmp/test_socket";
unlink($socket_path);

my $socket = IO::Socket::UNIX->new(
    Local  => $socket_path,
    Type   => SOCK_STREAM,
    Listen => 1,
);

die "Can't create socket: $!" unless $socket;

print "waiting for connections\n";

while (1) {
    my $client;

    do {
        $client = $socket->accept;
    } until ( defined($client) );

    my $thr = threads->new( \&processit, $client )->detach();
}

sub processit {
    my ($client) = @_;

    if($client->connected){
         print $client "Hello from server\n";

         while(<$client>) { print "$_\n" };
    }
    close( $client );
}

Client :

#!/usr/bin/env node

var net = require('net'),
    fs = require('fs'),
    sock;

var c = net.createConnection('/tmp/test_socket');

c.on('connect', function(socket) {
    console.log('connected');
    c.write("Hello from NodeJS");
    c.on('data', function(data) { console.log('perl: '+data.toString()) });
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top