Reputation: 189
Do you know if it's possible actually to disconnect a rtmpconnection and how ? There is no "disconnect" method in the official doc, and also in the rtmpconnection.lzx . So if you know a way out to disconnect the rtmp connection,please let me know. Thanks in advance.
Upvotes: 1
Views: 1484
Reputation: 8996
The <rtmpconnection> class in OpenLaszlo uses the ActionScript 3 NetConnection class to connect to the server. The NetConnection class has a method close(), here is the documentation for that:
Closes the connection that was opened locally or to the server and dispatches a netStatus event with a code property of NetConnection.Connect.Closed.
This method disconnects all NetStream objects running over the connection. Any queued data that has not been sent is discarded. (To terminate local or server streams without closing the connection, use NetStream.close().) If you close the connection and then want to create a new one, you must create a new NetConnection object and call the connect() method again.
The close() method also disconnects all remote shared objects running over this connection. However, you don't need to recreate the shared object to reconnect. Instead, you can just call SharedObject.connect() to reestablish the connection to the shared object. Also, any data in the shared object that was queued when you issued NetConnection.close() is sent after you reestablish a connection to the shared object.
With Flash Media Server, the best development practice is to call close() when the client no longer needs the connection to the server. Calling close() is the fastest way to clean up unused connections. You can configure the server to close idle connections automatically as a back-up measure.
In the LZX source code for the <rtmpconnection> I can see that NetConnection.close() is only called in case of a connection failure:
<!--- Handle connection failure, attempt to reconnect using altsrc
@keywords private -->
<method name="_handleConnectionFailure" args="msg"><![CDATA[
this._nc.close();
if (this.debug) {
if ($debug) Debug.warn("error connecting to", this._connecturl, ":", msg);
}
....
I don't know why there is no close method defined on the <rtmpconnection> class, but you could add that code for your yourself, by extending the <rtmpconnection> and adding a close method. Just make sure you handle the state variables correctly.
As I haven't used Red5 in a long time, I cannot tell you if Red5 automatically closes NetConnections which are idle.
Upvotes: 1