This example shows how to manage connections from both the application client and the server-side code.
In the client code, you need to check for specific connection codes and handle them. Create live streams or play recorded streams only when the client receives NetConnection.Connect.Success. When the client receives NetConnection.Connect.AppShutDown, all streams from server to client or client to server are shut down. In that case, close the connection to the server.
public function netStatusHandler(event:NetStatusEvent):void
{
trace("connected is: " + nc.connected );
trace("event.info.level: " + event.info.level);
trace("event.info.code: " + event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
trace("Congratulations! you're connected");
// create live streams
// play recorded streams
break;
case "NetConnection.Connect.Rejected":
trace ("Oops! the connection was rejected");
// try to connect again
break;
case "NetConnection.Connect.Failed":
trace("The server may be down or unreachable");
// display a message for the user
break;
case "NetConnection.Connect.AppShutDown":
trace("The application is shutting down");
// this method disconnects all stream objects
nc.close();
break;
case "NetConnection.Connect.Closed":
trace("The connection was closed successfully - goodbye");
// display a reconnect button
break;
}
}
nc.connect("rtmp://localhost/HelloServer");
RootInstall/applications/HelloServer
nc.connect("rtmp://localhost/MyApplication");
If the connection is successful, you should see output like this:
connected is: true event.info.level: status event.info.code: NetConnection.Connect.Success Congratulations! you're connected [SWF] C:\samples\SimpleConnectManage\bin\SimpleConnectManage-debug.swf - 2,377 bytes after decompression