Skip to content

Instantly share code, notes, and snippets.

Created July 6, 2011 22:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
RocketAMF Socket Example
require 'rubygems'
require 'socket'
require 'rocketamf'
class Animal
attr_accessor :name, :age
RocketAMF::ClassMapper.define do |m| :as => 'Animal', :ruby => 'Animal'
server =
loop {
client = server.accept
animal = = "Zebra"
animal.age = 5
client.write RocketAMF.serialize(animal, 3)
package {
import flash.display.Sprite;
import org.rackAMF.*;
public class SocketTest extends Sprite {
private var socket:Socket;
public function SocketTest() {
registerClassAlias('Animal', Animal);
socket = new Socket();
socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);
socket.connect("localhost", 8081);
private function onResponse(e:ProgressEvent):void {
var animal:Animal = socket.readObject() as Animal;
trace(Object(animal).constructor); // [trace] [class Animal]
trace(; // [trace] Zebra
trace(animal.age); // [trace] 5
class Animal {
public var name:String;
public var age:int;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment