Project

rubarb

0.0
No commit activity in last 3 years
No release in over 3 years
This library uses two socket connections between a client and a server. One is used for request / replies from the client to the server. The other is used for remote calls made from the server to the client. Each end publishes a single object on which methods can be called by the remote end. All calls to the remote objects are asyncronous. Do not make any blocking calls in the published object. Responses are return by calling the "reply method on the responder object.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 1.3.0

Runtime

>= 1.0.0.rc.4
= 1.3
 Project Readme

rubaRb

A Bidirectional Event Machine Based Remote Procedure Call Library for Ruby

This library uses two socket connections between a client and a server. One is used for request / replies from the client to the server. The other is used for remote calls made from the server to the client.

Each end publishes a single object on which methods can be called by the remote end. All calls to the remote objects are asyncronous. Do not make any blocking calls in the published object. Responses are return by calling the "reply" method on the responder object.

Server and Connection object may be created and started outside of EM::run, but the Eventmachine reactor must be started somewhere in your application

Compilation

$ rake build

Installation

$ gem install rubarb

Server Example

class ServerApi
  def time(responder)
    puts "Server received time request"
    responder.reply(Time.now)
  end
end

EM.run do
  server = Rubarb::Server.new("127.0.0.1", 9441, ServerApi.new)

  connections = {}

  server.start do |client|
    puts "Connection Made:  #{client}"
    client.name do |name|
      connections[name] = client
      client.errback do
        puts "Connection Lost:  #{name}"
        connections.delete(name)
      end

    end

  end

  EventMachine.add_periodic_timer(1) { puts "Connections:  #{connections.keys.inspect}" }

end

Client Example

class ClientApi
  def initialize(name)
    @name = name
  end
  def name(responder)
    responder.reply(@name)
  end
end

EM::run do
  connection = Rubarb::Connection.new("127.0.0.1", 9441, ClientApi.new(ARGV[0]))
  connection.errback do |error|
    puts ("Connection Error:  #{error}")
  end

  connection.start do
    connection.time do |response|
      puts "Server Said it is:  #{response.strftime("%D")}"
    end

    EventMachine.add_timer(20) do
      puts "stopping"
      connection.stop
      EM::stop
    end
  end

end

Building

$ gem install jeweller
$ rake build