Exemplo n.º 1
0
        /// <summary>
        /// Connects to a remote shared object on the server through the specified connection. Use this method after
        /// issuing SharedObject.GetRemote(...). After a successful connection, the sync event is dispatched.
        /// </summary>
        /// <param name="connection">A NetConnection object (such as one used to communicate with Flash Media Server) that is using the Real-Time Messaging Protocol (RTMP).</param>
        /// <param name="parameters">Parameters.</param>
        public void Connect(NetConnection connection, string parameters)
        {
            if (_initialSyncReceived)
            {
                throw new InvalidOperationException("SharedObject already connected");
            }
            ValidationUtils.ArgumentNotNull(connection, "connection");
            ValidationUtils.ArgumentNotNull(connection.Uri, "connection");
            ValidationUtils.ArgumentConditionTrue(connection.Uri.Scheme == "rtmp", "connection", "NetConnection object must use the Real-Time Messaging Protocol (RTMP)");
            ValidationUtils.ArgumentConditionTrue(connection.Connected, "connection", "NetConnection object must be connected");
            _connection          = connection;
            _initialSyncReceived = false;

            FluorineFx.Messaging.Rtmp.SO.SharedObjectMessage message;
            if (connection.ObjectEncoding == ObjectEncoding.AMF0)
            {
                message = new FluorineFx.Messaging.Rtmp.SO.SharedObjectMessage(_name, _version, _persistentSO);
            }
            else
            {
                message = new FluorineFx.Messaging.Rtmp.SO.FlexSharedObjectMessage(_name, _version, _persistentSO);
            }
            FluorineFx.Messaging.Rtmp.SO.SharedObjectEvent evt = new FluorineFx.Messaging.Rtmp.SO.SharedObjectEvent(FluorineFx.Messaging.Rtmp.SO.SharedObjectEventType.SERVER_CONNECT, null, null);
            message.AddEvent(evt);
            _connection.NetConnectionClient.Write(message);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Closes the connection between a remote shared object and the server.
        /// </summary>
        public void Close()
        {
            if (_initialSyncReceived && _connection != null && _connection.Connected)
            {
                FluorineFx.Messaging.Rtmp.SO.SharedObjectMessage message;
                if (_connection.ObjectEncoding == ObjectEncoding.AMF0)
                {
                    message = new FluorineFx.Messaging.Rtmp.SO.SharedObjectMessage(_name, _version, _persistentSO);
                }
                else
                {
                    message = new FluorineFx.Messaging.Rtmp.SO.FlexSharedObjectMessage(_name, _version, _persistentSO);
                }
                FluorineFx.Messaging.Rtmp.SO.SharedObjectEvent evt = new FluorineFx.Messaging.Rtmp.SO.SharedObjectEvent(FluorineFx.Messaging.Rtmp.SO.SharedObjectEventType.SERVER_DISCONNECT, null, null);
                message.AddEvent(evt);
                _connection.NetConnectionClient.Write(message);

                // clear collections
                base.RemoveAttributes();
                _ownerMessage.Events.Clear();
            }
            _initialSyncReceived = false;
        }