Ejemplo n.º 1
0
        /// <summary>
        ///     Serializes and transmits a frame to the server
        /// </summary>
        /// <param name="Frame">
        ///     The <seealso cref="StompFrame"/> to send to the server
        /// </param>
        /// <exception cref="ArgumentException">
        ///     Thrown if
        ///     <list type="number">
        ///         <item>You attempt to serialize a frame class that has no <seealso cref="StompFrameType"/> attribute</item>
        ///         <item>You attempt to send a frame that is marked as server to client only</item>
        ///         <item>You fail to fill in a mandatory frame parameter</item>
        ///     </list>
        /// </exception>
        public void SendFrame(StompFrame Frame)
        {
            // Get some metadata about the frame that we'll need
            StompFrameType SFT = Frame.GetType().GetCustomAttribute <StompFrameType>();

            // Validate frame before doing anything else
            if (SFT == null)
            {
                throw new ArgumentException("Attempt to serialize frame without frame type attribute", "Frame");
            }

            if (SFT.Direction == StompFrameDirection.ServerToClient)
            {
                throw new ArgumentException("Attempt to send server frame from client", "Frame");
            }

            // Serialize the frame and convert to byte array
            byte[] Data = Frame.Serialize();

            // Now send the frame
            lock (_Client)
            {
                _Client.GetStream().Write(Data, 0, Data.Length);
                _Client.GetStream().WriteByte(0);
                _HeartbeatTxIntervalTimeout = _HeartbeatTxInterval;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Serializes and transmits a frame to the server
        /// </summary>
        /// <param name="Frame">
        ///     The <seealso cref="StompFrame"/> to send to the server 
        /// </param>
        /// <exception cref="ArgumentException">
        ///     Thrown if
        ///     <list type="number">
        ///         <item>You attempt to serialize a frame class that has no <seealso cref="StompFrameType"/> attribute</item>
        ///         <item>You attempt to send a frame that is marked as server to client only</item>
        ///         <item>You fail to fill in a mandatory frame parameter</item>
        ///     </list>
        /// </exception>
        public void SendFrame(StompFrame Frame)
        {
            // Get some metadata about the frame that we'll need
            StompFrameType SFT = Frame.GetType().GetCustomAttribute<StompFrameType>();

            // Validate frame before doing anything else
            if (SFT == null)
                throw new ArgumentException("Attempt to serialize frame without frame type attribute", "Frame");

            if (SFT.Direction == StompFrameDirection.ServerToClient)
                throw new ArgumentException("Attempt to send server frame from client", "Frame");

            // Serialize the frame and convert to byte array
            byte[] Data = Frame.Serialize();

            // Now send the frame
            lock (_Client)
            {
                _Client.GetStream().Write(Data, 0, Data.Length);
                _Client.GetStream().WriteByte(0);
                _HeartbeatTxIntervalTimeout = _HeartbeatTxInterval;
            }
        }