Skip to content

Instantly share code, notes, and snippets.

@rjungemann
Created January 15, 2010 00:45
Show Gist options
  • Save rjungemann/277665 to your computer and use it in GitHub Desktop.
Save rjungemann/277665 to your computer and use it in GitHub Desktop.
An example showing AMF over sockets b/w AS and Ruby
# use "git clone git://github.com/warhammerkid/rocket-amf.git" to install
# rocket-amf into your directory
require 'rubygems'
require 'eventmachine'
require 'rocket-amf/lib/rocketamf'
module SocketAMFSampleServer
def post_init
puts "Connecting: someone connected to the echo server!"
end
def receive_data data
puts RocketAMF.deserialize(data, 3).inspect
send_data RocketAMF.serialize({ "sent" => "hello again!" }, 3)
end
end
EventMachine::run do
EventMachine::start_server "127.0.0.1", 8081, SocketAMFSampleServer
end
package {
import flash.display.Sprite;
import flash.net.Socket;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
public class SocketAMFExample extends Sprite {
private var socket:Socket;
public function SocketAMFExample() {
socket = new Socket();
socket.addEventListener(Event.CONNECT, onConnect);
socket.addEventListener(Event.CLOSE, onClose);
socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);
socket.connect("localhost", 8081);
}
private function onConnect(e:Event):void {
trace("Connected!");
socket.writeObject({ "sending": "hello world" });
socket.flush();
}
private function onResponse(e:ProgressEvent):void {
trace(socket.readObject()["sent"]);
}
private function onError(e:IOErrorEvent):void {}
private function onClose(e:Event):void {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment