Packagenet.flashmog
Classpublic class RPCSocket
InheritanceRPCSocket Inheritance flash.net.Socket

RPCSocket extends XMLSocket, adding a couple of useful informational properties such as a the host, the port, an 'attempting to connect' indicator boolean, and an ability to route incoming socket messages to the appropriate method of the appropriate Service



Public Properties
 PropertyDefined by
  host : String
[read-only] property accessor func which returns this RPCSocket's host value
RPCSocket
  onConnect : Function
[write-only] Set function for the onConnect event handler of this Class
RPCSocket
  port : int
[read-only] property accessor func which returns this RPCSocket's port value
RPCSocket
  serializeMethod : String
A string specifying the serialization technique of this RPCSocket My intent with this variable was to allow a user to specify which serialization technique should be used for a given socket.
RPCSocket
  version : String = "0.3.1"
Just specifies a version
RPCSocket
Public Methods
 MethodDefined by
  
RPCSocket(hostArg:String, portArg:int, serializeMethodArg:String, logger:Log = null)
constructor function NOTE: unlike the base XMLSocket class, I REQUIRE the host and port arguments for this constructor.
RPCSocket
  
close():void
Closes the underlying XMLSocket
RPCSocket
  
connect(host:String, port:int):void
Connects the underlying XMLSocket This method validates both the host and port params previously supplied to the constructor, sets the boolWaitingForConnect boolean to true and then calls the connect method of the XMLSocket, returning whatever that returns.
RPCSocket
  
executeRPC(serviceName:String, methodName:String, methodParams:Array):void
Sends a request for the server to execute an RPC This method takes the given parameters and from them generates a well-formed RPC request according to the FlashMOG protocol.
RPCSocket
  
Registers a Service object with this RPCSocket When a Service object attempts to connect to a particular host and port, it is referred to an existing socket connection via the static methods of the ConnectionPool Class.
RPCSocket
  
unRegisterService(serviceNameArg:String):void
UnRegisters a service from the current RPCsocket This method works by making a copy of services without including the Service with a name matching serviceNameArg.
RPCSocket
Public Constants
 ConstantDefined by
  BUFFER_STATE_READING : * = 1
[static]
RPCSocket
  BUFFER_STATE_READY : * = 0
[static]
RPCSocket
  MAX_BUFFER_LENGTH : * = 10000000
[static]
RPCSocket
  MESSAGE_LENGTH_INDICATOR_BYTES : * = 4
[static]
RPCSocket
  SERIALIZE_METHOD_AMF3 : String = "AMF3"
[static]
RPCSocket
  SERIALIZE_METHOD_JSON : String = "JSON"
[static]
RPCSocket
  SERIALIZE_METHOD_PHP : String = "PHP"
[static] class constants
RPCSocket
  SERIALIZE_METHOD_XML : String = "XML"
[static]
RPCSocket
Property detail
hostproperty
host:String  [read-only]

property accessor func which returns this RPCSocket's host value

Implementation
    public function get host():String
onConnectproperty 
onConnect:Function  [write-only]

Set function for the onConnect event handler of this Class

Implementation
    public function set onConnect(value:Function):void
portproperty 
port:int  [read-only]

property accessor func which returns this RPCSocket's port value

Implementation
    public function get port():int
serializeMethodproperty 
public var serializeMethod:String

A string specifying the serialization technique of this RPCSocket My intent with this variable was to allow a user to specify which serialization technique should be used for a given socket. As of this writing, I have not yet figured out how to expose this property to Services because two distinct Services could in theory try to specify different serialization techniques but share a single RPCSocket. What to do?

versionproperty 
public var version:String = "0.3.1"

Just specifies a version

Constructor detail
RPCSocket()constructor
public function RPCSocket(hostArg:String, portArg:int, serializeMethodArg:String, logger:Log = null)

constructor function NOTE: unlike the base XMLSocket class, I REQUIRE the host and port arguments for this constructor. I do this to avoid potential consistency problems should one service construct and connect an RPCSocket with one host/port combination and then a subsequent try to connect using another while we are still waiting for the first connection. This might be a big inconvenient as we must create a new XMLSocket to connect to a different host/port but that is how the classes work that use this class so it should not be a problem. The advantage we gain by requiring host & port here is that we no longer need these values for the connect() method.

Parameters
hostArg:String — hostArg the IP or host name of the socket server
 
portArg:int — portArg the port integer where the server is listening for sockets connex
 
serializeMethodArg:String — serializeMethodArg string ID to specify what serialization technique is to be used for transmission of RPC requests across the socket. Should match one of the SERIALIZE_METHOD_class constants
 
logger:Log (default = null) — logger the object to handle log.write commands
Method detail
close()method
public override function close():void

Closes the underlying XMLSocket

connect()method 
public override function connect(host:String, port:int):void

Connects the underlying XMLSocket This method validates both the host and port params previously supplied to the constructor, sets the boolWaitingForConnect boolean to true and then calls the connect method of the XMLSocket, returning whatever that returns.

Parameters
host:String — hostArg - a host argument which is ignored in favor of the value supplied in the constructor
 
port:int — portArg - a host argument which is ignored in favor of the value supplied in the constructor
executeRPC()method 
public function executeRPC(serviceName:String, methodName:String, methodParams:Array):void

Sends a request for the server to execute an RPC This method takes the given parameters and from them generates a well-formed RPC request according to the FlashMOG protocol. A well-formed RPC request is a serialized array with 3 elements: - 0 a service name - 1 a method name - 2 the parameters to apply the method to Serialization techniques may eventually vary but as of this writing they are limited to PHP Serialization. Sephiroth's AS3 serializer class is used to implement the serialization client-side

Parameters
serviceName:String — serviceName the name of the target service class on the server
 
methodName:String — methodName the name of the target method of the server-side service
 
methodParams:Array — methodParams an array containing parameters to be processed by the method
registerService()method 
public function registerService(svc:FlashMOGService):Boolean

Registers a Service object with this RPCSocket When a Service object attempts to connect to a particular host and port, it is referred to an existing socket connection via the static methods of the ConnectionPool Class. If one exists and it is 'registered' to that socket via this function the net effect is that a reference to the Service is stored in this RPCSocket's services array. If none exists, a new one is created and the Service is then registered that new RPCSocket

Parameters
svc:FlashMOGService — svc the Service object being registered

Returns
Boolean
unRegisterService()method 
public function unRegisterService(serviceNameArg:String):void

UnRegisters a service from the current RPCsocket This method works by making a copy of services without including the Service with a name matching serviceNameArg. If no services are left or the remaining ones are not using the socket, the socket closes itself

Parameters
serviceNameArg:String — serviceNameArg the name of the Service object being UnRegistered
Constant detail
BUFFER_STATE_READINGconstant
public static const BUFFER_STATE_READING:* = 1
BUFFER_STATE_READYconstant 
public static const BUFFER_STATE_READY:* = 0
MAX_BUFFER_LENGTHconstant 
public static const MAX_BUFFER_LENGTH:* = 10000000
MESSAGE_LENGTH_INDICATOR_BYTESconstant 
public static const MESSAGE_LENGTH_INDICATOR_BYTES:* = 4
SERIALIZE_METHOD_AMF3constant 
public static const SERIALIZE_METHOD_AMF3:String = "AMF3"
SERIALIZE_METHOD_JSONconstant 
public static const SERIALIZE_METHOD_JSON:String = "JSON"
SERIALIZE_METHOD_PHPconstant 
public static const SERIALIZE_METHOD_PHP:String = "PHP"

class constants

SERIALIZE_METHOD_XMLconstant 
public static const SERIALIZE_METHOD_XML:String = "XML"