Packagecom.electrotank.electroserver4
Classpublic class ElectroServer
InheritanceElectroServer Inheritance Observable

The ElectroServer class is the most-used clsas in the ElectroServer API. You use it to send requests to the server, create new server connections, create an RTMP connection, and to get at the managered zones, rooms, and users.



Public Methods
 MethodDefined by
  
Creates a new ElectroServer class instance.
ElectroServer
  
addBuddy(name:String, esob:EsObject):void
Adds a user to the client's buddy list.
ElectroServer
 Inherited
addEventListener(mt:MessageType, funcName:String, scope:Object, first:Boolean = false):void
Observable
 Inherited
addListener(ob:Object):void
Observable
  
close():void
Closes all open connections with ElectroServer
ElectroServer
  
Closes the RtmpConnection.
ElectroServer
  
createConnection(ip:String, port:Number):Connection
Creates a new Connection instance and returns it.
ElectroServer
  
createHttpConnection(ip:String, port:Number):HttpConnection
Creates a new HttpConnection instance and returns it.
ElectroServer
  
createRtmpConnection(ip:String, port:Number):RtmpConnection
Creates a new RtmpConnection with ElectroServer.
ElectroServer
 Inherited
dispatchEvent(eventOb:MessageImpl):void
Observable
  
getBuddyList():Object
Returns an Object of of buddies stored by user name.
ElectroServer
  
Gets the list of open connections.
ElectroServer
  
getDebug():Boolean
Gets the debug status and returns it as a Boolean value.
ElectroServer
  
getIsLoggedIn():Boolean
Returns true if the client is logged in and false if not logged in.
ElectroServer
  
getProtocol():String
Gets the protocol being used.
ElectroServer
  
Returns the RtmpConnection.
ElectroServer
  
Returns the UserManager instance.
ElectroServer
  
Returns the ZoneManager.
ElectroServer
 Inherited
notifyListeners(eventName:String, eventOb:Object):void
Observable
  
onBinaryData(ev:Object):void
ElectroServer
  
removeBuddy(name:String):void
Removes a buddy from the buddy list.
ElectroServer
 Inherited
removeEventListener(mt:MessageType, funcName:String, scope:Object):void
Observable
 Inherited
removeListener(ob:Object):void
Observable
  
Sends a request or response object to the server.
ElectroServer
  
setDebug(debug:Boolean):void
This method is used to toggle all message taffic from being traced in the output console.
ElectroServer
  
setProtocol(protocol:String):void
Sets the protocol.
ElectroServer
  
startSimulatingLatency(latency:Number):void
This method starts a latency simulation.
ElectroServer
  
Stops the latency simulation.
ElectroServer
Constructor detail
ElectroServer()constructor
public function ElectroServer()

Creates a new ElectroServer class instance.

Method detail
addBuddy()method
public function addBuddy(name:String, esob:EsObject):void

Adds a user to the client's buddy list. The list is maintained by the server. Buddy online/offline status updates are sent to the client.

Parameters
name:String — name The buddy's user name.
 
esob:EsObject — esob An EsObject to store with the buddy entry.

See also

close()method 
public function close():void

Closes all open connections with ElectroServer

See also

createConnection
createRtmpConnection
com.electrotank.electroserver4.message.event.RtmpConnectionClosedEvent
closeRtmpConnection()method 
public function closeRtmpConnection():void

Closes the RtmpConnection.

See also

createRtmpConnection
com.electrotank.electroserver4.rtmpconnection.RtmpConnection
com.electrotank.electroserver4.message.event.RtmpConnectionClosedEvent

Example
Closes the RTMP connection.
                     import com.electrotank.electroserver4.ElectroServer;
                    var es:ElectroServer;//created and connected somewhere else
                    es.closeRtmpConnection();
                

createConnection()method 
public function createConnection(ip:String, port:Number):Connection

Creates a new Connection instance and returns it. Internally a new XMLSocket (string protocol) or Socket (AS3 binary) is created and used to communicate with the server via text or binary protocol.

Parameters
ip:String
 
port:Number

Returns
Connection

See also

com.electrotank.electroserver4.connection.Connection
com.electrotank.electroserver4.message.event.ConnectionEvent

Example
                     import com.electrotank.electroserver4.ElectroServer;
                     import com.electrotank.electroserver4.connection;
                    import com.electrotank.electroserver4.message.MessageType;
                    import com.electrotank.electroserver4.message.event.
                    //
                    var es:ElectroServer = new ElectroServer();
                    es.addEventListener(MessageType.ConnectionEvent, "onConnectionEvent", this);
                    public function onConnectionEvent(e:ConnectionEvent):void {

                        if (e.getAccepted()) {
                            //connection accepted
                        } else {
                            //connection failed
                        }
                    }
                

createHttpConnection()method 
public function createHttpConnection(ip:String, port:Number):HttpConnection

Creates a new HttpConnection instance and returns it. Internally a new URLLoader/URLRequest is created and used to communicate with the server via binary protocol.

Parameters
ip:String
 
port:Number

Returns
HttpConnection

See also

com.electrotank.electroserver4.connection.Connection
com.electrotank.electroserver4.message.event.ConnectionEvent

Example
                     import com.electrotank.electroserver4.ElectroServer;
                     import com.electrotank.electroserver4.connection;
                    import com.electrotank.electroserver4.message.MessageType;
                    import com.electrotank.electroserver4.message.event.
                    //
                    var es:ElectroServer = new ElectroServer();
                    es.addEventListener(MessageType.ConnectionEvent, "onConnectionEvent", this);
                    public function onConnectionEvent(e:ConnectionEvent):void {

                        if (e.getAccepted()) {
                            //connection accepted
                        } else {
                            //connection failed
                        }
                    }
                

createRtmpConnection()method 
public function createRtmpConnection(ip:String, port:Number):RtmpConnection

Creates a new RtmpConnection with ElectroServer. RtmpConnection is used to create new NetStream instances that are used to publish or subscribe to audio and video streams. RtmpConnection internally creates a NetConnection class instance to manage its connection with ElectroServer using the Flash player's built-in RTMP support.

Parameters
ip:String
 
port:Number

Returns
RtmpConnection — RtmpConnection

See also

flash.net.NetStream
flash.net.NetConnection

Example
This example shows how to use the createRtmpConnection method:
                     import com.electrotank.electroserver4.ElectroServer;
                    import com.electrotank.electroserver4.message.MessageType;
                    import com.electrotank.electroserver4.message.event.RtmpConnectionEvent;
                    var es:ElectroServer;
                     var ip:String = "127.0.0.1";
                     var port:Number = 1935;
                     es.addEventListener(MessageType.RtmpConnectionEvent, "onRtmpConnection", this);
                     es.createRtmpConnection(ip, port);
                    public function onRtmpConnection(e:RtmpConnectionEvent):void {

                        if (e.getAccepted()) {
                            //connection accepted
                        } else {
                            //connecton failed
                        }
                    }
                    

getBuddyList()method 
public function getBuddyList():Object

Returns an Object of of buddies stored by user name.

Returns
Object — Object containing buddies by user name.

See also

getConnections()method 
public function getConnections():Array

Gets the list of open connections.

Returns
Array — Array of connections. Each element is of type Connection
getDebug()method 
public function getDebug():Boolean

Gets the debug status and returns it as a Boolean value. If debugging is turned on then message traffic is traced to the output window in the Flash IDE and logged.

Returns
Boolean — The debug status as a Boolean.

See also

getIsLoggedIn()method 
public function getIsLoggedIn():Boolean

Returns true if the client is logged in and false if not logged in.

Returns
Boolean

Example
Get your logged in status.
                     import com.electrotank.electroserver4.ElectroServer;
                    var es:ElectroServer;//created and connected somewhere else
                    var isLoggedIn:Boolean = es.getIsLoggedIn();
                    

getProtocol()method 
public function getProtocol():String

Gets the protocol being used.

Returns
String — The protocol being used.
getRtmpConnection()method 
public function getRtmpConnection():RtmpConnection

Returns the RtmpConnection.

Returns
RtmpConnection — RtmpConnection

See also


Example
                     import com.electrotank.electroserver4.ElectroServer;
                     import com.electrotank.electroserver4.rtmpconnection.RtmpConnection;
                    //
                    var es:ElectroServer;//created and already connected somewhere else
                    var rtmpConnection:RtmpConnection = es.getRtmpConnection();
                

getUserManager()method 
public function getUserManager():UserManager

Returns the UserManager instance. The UserManager is used to keep track of users that you should be able to see. If you see a user in multiple rooms it points back to the same User instance.

Returns
UserManager — Returns the UserManager

See also

getZoneManager()method 
public function getZoneManager():ZoneManager

Returns the ZoneManager. One instance of ZoneManager exists and keeps track of the zones.

Returns
ZoneManager — Returns the ZoneManager instance.

See also


Example
Get the zone manager and loop through its list of rooms tracing out the room names.
                     import com.electrotank.electroserver4.ElectroServer;
                     import com.electrotank.electroserver4.connection;
                    import com.electrotank.electroserver4.message.MessageType;
                    import com.electrotank.electroserver4.message.event.
                    //
                    var es:ElectroServer;//created and connected somewhere else
                     var zm:ZoneManager = es.getZoneManager();
                     var rooms:Array = zm.getZone("Lobby Zone").getRooms();
                     for (var i:Number=0;i

onBinaryData()method 
public function onBinaryData(ev:Object):voidParameters
ev:Object
removeBuddy()method 
public function removeBuddy(name:String):void

Removes a buddy from the buddy list.

Parameters
name:String — The user name of the buddy to remove.

See also

send()method 
public function send(message:Message):SendStatus

Sends a request or response object to the server. A client can only communicate with the server via this method and via RtmpConnection.

Parameters
message:Message — The request object to send to the server. This is one of the most commonly used methods of the ElectroServer class. First you build a request object and populate it with information (such as LoginRequest), and then you send it using this method. The message is first validated before the API sends it. If the messages fails validation then SendStatus.getIsSent() returns false.

Returns
SendStatus — Returns a SendStatus object which contains information saying if the message passed validation and was sent, or not.

See also


Example
                     import com.electrotank.electroserver4.ElectroServer;
                    import com.electrotank.electroserver4.message.request.LoginRequest;
                    import com.electrotank.electroserver4.message.response.LoginResponse;
                    import com.electrotank.electroserver4.message.MessageType;
                     //Build a request, send it, capture the response
                    var lr:LoginRequest = new LoginRequest();
                    lr.setUserName("McLovin");
                    es.send(lr);
                    //
                    public function onLoginResponse(e:LoginResponse):void {

                        if (e.getAccepted()) {
                            //login accepted
                        } else {
                            //login failed
                        }
                    }
                

setDebug()method 
public function setDebug(debug:Boolean):void

This method is used to toggle all message taffic from being traced in the output console. Pass in true or false to enable or disable log messages getting traced to the output window in the Flash IDE. If debugging is on then all message traffic is traced to the output window when the onLog event is called. You can listen for log events directly by using the Logger class.

Parameters
debug:Boolean — True or false to enable/disable log messages tracing to the output window.

See also

setProtocol()method 
public function setProtocol(protocol:String):void

Sets the protocol. The default is Protocol.TEXT. Valid options are Protocol.TEXT and Protocol.BINARARY (AS3 and above).

Parameters
protocol:String — The protocol to use.
startSimulatingLatency()method 
public function startSimulatingLatency(latency:Number):void

This method starts a latency simulation. The actual latency simulated will be the real latency of this client plus the value passed in here.

Parameters
latency:Number — The latency to simulate.
stopSimulatingLatency()method 
public function stopSimulatingLatency():void

Stops the latency simulation.