Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

AMF Socket - Ruby

This library is an implementation of AMF Socket for Ruby's EventMachine.

Installation

Add these lines to your application's Gemfile:

gem 'RocketAMF', :git => 'https://github.com/rubyamf/rocketamf.git'
gem 'eventmachine'
gem 'amf_socket'

This gem requires the latest RocketAMF master code because it uses strings (instead of symbols) when encoding/decoding hashes. Failure to follow this requirement will result in exceptions.

And then execute:

$ bundle

Or install it yourself as:

$ gem install amf_socket

Usage

require 'eventmachine'
require 'RocketAMF'
require 'amf_socket'

EM.run do
  class MyConnection < AmfSocket::AmfRpcConnection
    def post_init
      super

      puts 'Connected.'

      puts 'Sending a request.'
      send_request('hello', :foo => 'bar') do |request|
        request.succeeded do |response|
          puts "Request received a response. result=#{response.result}"
        end

        request.failed do |reason|
          puts "Request failed to receive a response. reason=#{reason}"
        end
      end

      puts 'Sending a message.'
      send_message('hey there', :bar => ['hello', 'world'])
    end

    def receive_request(request)
      puts "Received a request. command=#{request.command}, params=#{request.params}"
      request.reply('Here is my response')
    end

    def receive_message(message)
      puts "Received a message. command=#{message.command}, params=#{message.params}"
    end

    def unbind
      super

      puts 'Disconnected.'
    end
  end

  EM.start_server('localhost', 9000, MyConnection)
end

Policy Server

Newer versions of the Flash runtime require a valid policy file before socket connections are permitted. This gem includes a simple policy connection class for delivering this file. Note that you will need run the below code as root on Linux/UNIX since it uses a port number less 1024. It is recommended you run the policy server in a separate process from your application code in order to minimize security risks.

require 'eventmachine'
require 'RocketAMF'
require 'amf_socket'

EM.run do
  EM.start_server('0.0.0.0', 843, AmfSocket::PolicyConnection)
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2012 Chad Remesch. See LICENSE.txt for further details.

About

Ruby (EventMachine) implementation of AMF Socket.

Resources

License

Packages

No packages published

Languages