rinterface: a pure Ruby client to talk to Erlang

May 20, 2009

After digging through the jinterface code for the past couple of evenings I finally have a working Ruby client that can make RPC calls to an Erlang node. Although the code is a bit rough right now, it works.

I’m hoping to evolve it into a full Ruby node with capabilities similar to jinterface (the java implementation included with the Erlang).

The current implementation has a few limitations:

  1. The Erlang node and Ruby client must be running on the same machine. This will not be hard to change
  2. The Erlang process must have a registered name

Essentially right now it works a lot like the native rpc:call in Erlang.

Here’s an example of a Ruby client calling a Erlang process called ‘math’:


EM.run do
  # Connect to epmd to get the port of 'math'.
  # 'math' is the -sname of the erlang node
  epmd = EpmdConnection.lookup_node("math")
  epmd.callback do |port|
    puts "got the port #{port}"

    # make the rpc call to 'math' on port for
    # mod 'math_server' on fun 'add' with args
    node = Node.rpc_call("math",port.to_i,
                                  "math_server",
                                  "add",[10,20])
    node.callback{ |result|
      puts "Sum is: #{result}"
      EM.stop
    }

    node.errback{ |err|
      puts "Error: #{err}"
      EM.stop
    }
  end

  epmd.errback do |err|
    puts "Error: #{err}"
    EM.stop
  end
end

You can check out the code here: rinterface

Trackbacks

Unfortunately, due to spammers I've had to close both trackbacks and comments.

Comments

Leave a response

Comments