Table Of Contents

Previous topic

Execute a user program in parallel

Next topic

Work with various network protocols

This Page

Call a user program from various programming languages

Once a user program run on RaSC following the steps in Run a user program as a RaSC service, the user program can be easily called from various programming languages through MessagePack RPC.

The following shows examples of calling a user program running on RaSC. The example assumes that SERVICE_HOST and SERVICE_PORT are the host and the port of the RaSC service.

Call from Perl

This example requires AnyEvent::MPRPC.

#!/bin/env perl

use strict;
use warnings;
use utf8;
use AnyEvent::MPRPC;
use AnyEvent::MPRPC::Client;

my $client = AnyEvent::MPRPC::Client->new(
  host => "SERVICE_HOST",
  port => "SERVICE_PORT"
);
my $res = $client->call( 'analyze' => 'String to be analyzed' )->recv;
print "$res\n";

my $reqArray = [ "First sentence", "Second sentence" ];
my $resArray = $client->call( 'analyzeArray' => [ $reqArray ] )->recv;
print join("\n", @$resArray);

Call from Python

This example requires msgpackrpc.

# coding:utf-8

import msgpackrpc

client = msgpackrpc.Client(msgpackrpc.Address(
   "SERVICE_HOST", SERVICE_PORT))
result = client.call('analyze', "String to be analyzed")
print(result)

resultArray = client.call('analyzeArray', [ "First sentence", "Second sentence" ])
print("\n".join(resultArray))

Call from Ruby

This example requires msgpack-rpc.

# -*- coding: utf-8 -*-
require 'msgpack/rpc'

client = MessagePack::RPC::Client.new('SERVICE_HOST', SERVICE_PORT)

result = client.call(:analyze, "String to be analyzed")
print(result)

resultArray = client.call(:analyzeArray, [ "First sentence", "Second sentence" ])
print(resultArray.join("\n"))