Ejemplo n.º 1
0
        /// <summary>
        /// This method sends a PDU on the socket session
        /// </summary>
        /// <param name="pdu"></param>
        /// <returns></returns>
        internal bool SendPdu(SmppPdu pdu)
        {
            if (sock_.IsConnected)
            {
                try
                {
                    FireEvent(EventType.PostProcessPdu, new SmppEventArgs(this, pdu));
                }
                catch
                {
                }

                try
                {
                    SmppByteStream bs = new SmppByteStream();
                    pdu.Serialize(new SmppWriter(bs, this.version_));
                    sock_.Send(bs.GetBuffer());
                    return(true);
                }
                catch (System.Net.Sockets.SocketException ex)
                {
                    sock_.Close(true);
                    FireEvent(EventType.SessionDisconnected, new SmppDisconnectEventArgs(this, ex));
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method adds the PDU to the given byte stream.
        /// </summary>
        /// <param name="stm"></param>
        public void Serialize(SmppWriter stm)
        {
            bool           includeBody = (this.Status == StatusCodes.ESME_ROK);
            int            length = REQUIRED_SIZE;
            byte           version = stm.Version;
            SmppByteStream body = null, optBody = null;

            // Get the optional (Tlv) parameters
            if (includeBody == true)
            {
                // Serialize the body into a stream.
                body = new SmppByteStream();
                new SmppWriter(body, version).Add(this);
                length += (int)body.Length;

                // If we are using at least V3.4 of the SMPP spec
                // then include Tlvs, otherwise we do not.
                if (version >= SmppVersion.SMPP_V34)
                {
                    int size = optionalParameters_.Count;
                    if (size > 0)
                    {
                        optBody = new SmppByteStream();
                        SmppWriter writer = new SmppWriter(optBody, version);

                        for (int i = 0; i < size; i++)
                        {
                            TlvParameter tlv = (TlvParameter)optionalParameters_[i];
                            if (tlv != null && tlv.HasValue)
                            {
                                writer.Add(tlv);
                            }
                        }

                        // Add the length of all optional parameters
                        length += (int)optBody.Length;
                    }
                }
            }

            // Now serialize the whole thing together.
            stm.Add(length);
            stm.Add(CommandId);
            stm.Add(status_);
            stm.Add(sequenceNumber_);
            if (includeBody == true)
            {
                if (body != null && body.Length > 0)
                {
                    stm.Add(body);
                }
                if (optBody != null && optBody.Length > 0)
                {
                    stm.Add(optBody);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// This is used for diagnostics - it places the PDU into binary
 /// byte array form.
 /// </summary>
 /// <returns>Byte array</returns>
 public string ToString(string fmt)
 {
     if (fmt.ToLower() == "b")
     {
         SmppByteStream stm    = new SmppByteStream();
         SmppWriter     writer = new SmppWriter(stm);
         this.Serialize(writer);
         return(stm.ToString());
     }
     else
     {
         return(this.ToString());
     }
 }