To connect a NetConnection object to a RTMP server set up a gateway connection using a RTMP URL:
rtmp://host[:port]/appName
Example URLs:
For RTMP connections a persistent connection is made to the RTMP server. The NetConnection object will dispatch events from various stages of the data flow.
Sample
using FluorineFx.Net;
...
NetConnection netConnection = new NetConnection();
netConnection.OnConnect += new ConnectHandler(netConnection_OnConnect);
netConnection.NetStatus += new NetStatusHandler(netConnection_NetStatus);
netConnection.Connect("rtmp://localhost:1935/HelloWorld");
...
void netConnection_OnConnect(object sender, EventArgs e)
{
//The NetConnection object is connected now
netConnection.Call("serverHelloMsg", new ServerHelloMsgHandler(), "some text");
}
...
void netConnection_NetStatus(object sender, NetStatusEventArgs e)
{
string level = e.Info["level"] as string;
}
...
//Our result handler object
public class ServerHelloMsgHandler : IPendingServiceCallback
{
public void ResultReceived(IPendingServiceCall call)
{
object result = call.Result;
}
}
The RemoteSharedObject API can be used to read and store data on a RTMP server. You can open a remote shared object that stores real-time data, get notifications about updates, send and receive messages.
Sample
using FluorineFx.Net;
...
RemoteSharedObject sharedObject;
NetConnection netConnection = new NetConnection();
netConnection.OnConnect += new ConnectHandler(netConnection_OnConnect);
netConnection.NetStatus += new NetStatusHandler(netConnection_NetStatus);
netConnection.Connect("rtmp://localhost:1935/sotest");
...
void netConnection_OnConnect(object sender, EventArgs e)
{
sharedObject = RemoteSharedObject.GetRemote("users", netConnection.Uri.ToString(), false);
sharedObject.OnConnect += new ConnectHandler(sharedObject_OnConnect);
sharedObject.OnDisconnect += new DisconnectHandler(sharedObject_OnDisconnect);
sharedObject.NetStatus += new NetStatusHandler(sharedObject_NetStatus);
sharedObject.Sync += new SyncHandler(sharedObject_Sync);
sharedObject.Connect(netConnection);
}
...
void sharedObject_Sync(object sender, SyncEventArgs e)
{
ASObject[] changeList = e.ChangeList;
for (int i = 0; i < changeList.Length; i++)
{
ASObject info = changeList[i];
...
}
}
...
Note: You can derive your own shared object class from the RemoteSharedObject class and define methods to handle shared object messages. In this case you will specify the type of the RSO in the RemoteSharedObject.GetRemote call.
For more information, see the [FluorineFx InstallDir]\Samples\Misc\RtmpClient sample applications.