RocketAMF Socket Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'socket' | |
require 'rocketamf' | |
class Animal | |
attr_accessor :name, :age | |
end | |
RocketAMF::ClassMapper.define do |m| | |
m.map :as => 'Animal', :ruby => 'Animal' | |
end | |
server = TCPServer.open(8081) | |
loop { | |
client = server.accept | |
animal = Animal.new | |
animal.name = "Zebra" | |
animal.age = 5 | |
client.write RocketAMF.serialize(animal, 3) | |
client.close | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package { | |
import flash.display.Sprite; | |
import flash.net.registerClassAlias; | |
import org.rackAMF.*; | |
import flash.net.Socket; | |
import flash.events.*; | |
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(animal.name); // [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