Click here to Skip to main content
12,293,917 members (69,287 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads

Stats

168.2K views
9.4K downloads
65 bookmarked
Posted

STUN Client

, 20 Apr 2007 CPOL
STUN client C# implementation with sample application
Stun
Net
docs
dns
dns_records.jpg
dns_records.vsd
Net
_junk
_Obsolete
_Stuff
AUTH
bin
Release
LumiSoft.Net.dll
Data
Dns
Client
FTP
Client
Server
HTTP
Server
ICMP
IMAP
Client
Server
IO
Log
LumiSoft.Net
Mime
vCard
Net.csproj.user
Net.suo
NNTP
Client
POP3
Client
Server
SDP
ServersCore
SIP
Client
Message
Proxy
Stack
SMTP
Client
Server
STUN
Client
Message
STUN_Client_app
STUN_Client_app.suo
STUN_Client_app
bin
Debug
LumiSoft.Net.dll
STUN_Client_app.exe
STUN_Client_app.vshost.exe
dep
LumiSoft.Net.dll
Properties
using System;
using System.Collections.Generic;
using System.Text;

namespace LumiSoft.Net.SIP.Stack
{
    /// <summary>
    /// This is base class for SIP client and server transaction.
    /// </summary>
    public abstract class SIP_Transaction : IDisposable
    {
        private DateTime m_CreateTime;
        private bool     m_CanCreateDialog = false;

        /// <summary>
        /// Default constructor.
        /// </summary>
        public SIP_Transaction()
        {
            m_CreateTime = DateTime.Now;
        }

        #region method Dispose

        /// <summary>
        /// Cleans up any resources being used.
        /// </summary>
        public virtual void Dispose()
        {
            this.Canceled       = null;
            this.Terminated     = null;
            this.TimedOut       = null;
            this.TransportError = null;
        }

        #endregion


        #region method Cancel

        /// <summary>
        /// Cancels current transaction.
        /// </summary>
        public abstract void Cancel();

        #endregion


        #region method GetLastProvisionalResponse

        /// <summary>
        /// Gets last provisional(1xx) response from responses collection. Returns null if no provisional responses.
        /// </summary>
        /// <returns>Returns last provisional response or null if none exists.</returns>
        protected SIP_Response GetLastProvisionalResponse()
        {
            for(int i=this.Responses.Length - 1;i>-1;i--){
                if(this.Responses[i].StausCodeType == SIP_StatusCodeType.Provisional){
                    return this.Responses[i];
                }
            }

            return null;
        }

        #endregion

        #region method GetFinalResponse

        /// <summary>
        /// Gets final(2xx > 699) response from responses collection. Returns null if no final responses.
        /// </summary>
        /// <returns>Returns final response or null if none exists.</returns>
        internal protected SIP_Response GetFinalResponse()
        {
            foreach(SIP_Response response in this.Responses){
                if(response.StausCodeType != SIP_StatusCodeType.Provisional){
                    return response;
                }
            }

            return null;
        }

        #endregion


        #region Properties Implementation

        /// <summary>
        /// Gets transaction ID (Via: branch parameter value).
        /// </summary>
        public abstract string ID
        {
            get;
        }

        /// <summary>
        /// Gets time when this transaction was created.
        /// </summary>
        public DateTime CreateTime
        {
            get{ return m_CreateTime; }
        }

        /// <summary>
        /// Gets SIP request what caused to create this transaction.
        /// </summary>
        public abstract SIP_Request Request
        {
            get;
        }

        /// <summary>
        /// Gets transaction related responses.
        /// </summary>
        public abstract SIP_Response[] Responses
        {
            get;
        }

        /// <summary>
        /// Gets or sets if transaction can create SIP dialog.
        /// </summary>
        public bool CanCreateDialog
        {
            get{ return m_CanCreateDialog; }

            set{ m_CanCreateDialog = value; }
        }

        /// <summary>
        /// Gets transaction related SIP dialog. Returns null if no dialog available.
        /// </summary>
        public abstract SIP_Dialog Dialog
        {
            get;
        }

        #endregion

        #region Events Implementation

        /// <summary>
        /// Is raised if transaction is canceled.
        /// </summary>
        public event EventHandler Canceled = null;

        /// <summary>
        /// Raises Canceled event.
        /// </summary>
        protected void OnCanceled()
        {
            if(this.Canceled != null){
                this.Canceled(null,null);
            }
        }

        /// <summary>
        /// Is raised if transaction is terminated.
        /// </summary>
        public event EventHandler Terminated = null;

        /// <summary>
        /// Raises Terminated event.
        /// </summary>
        protected void OnTerminated()
        {
            if(this.Terminated != null){
                this.Terminated(this,new EventArgs());
            }
        }

        /// <summary>
        /// Is raised if transaction is timed out. 
        /// </summary>
        /// <remarks>
        /// TU(transaction user) MUST treat it as if a 408 (Request Timeout) status code 
        /// has been received (more info RFC 3261 8.1.3.).
        /// </remarks>
        public event EventHandler TimedOut = null;

        /// <summary>
        /// Raises TimedOut event.
        /// </summary>
        protected void OnTimedOut()
        {
            if(this.TimedOut != null){
                this.TimedOut(this,new EventArgs());
            }
        }

        /// <summary>
        /// Is raised when there is transport error. 
        /// </summary>
        /// <remarks>
        /// TU(transaction user) MUST treat it as if a 503 (Service Unavailable) status code 
        /// has been received (more info RFC 3261 8.1.3.).
        /// </remarks>
        public event EventHandler TransportError = null;

        /// <summary>
        /// Raises TimedOut event.
        /// </summary>
        protected void OnTransportError()
        {
            if(this.TransportError != null){
                this.TransportError(this,new EventArgs());
            }
        }

        /// <summary>
        /// Is raised when there is transaction error. For example this is raised when server transaction never
        /// gets ACK.
        /// </summary>
        public event EventHandler TransactionError = null;

        /// <summary>
        /// Raises TransactionError event.
        /// </summary>
        /// <param name="errorText">Text describing error.</param>
        protected void OnTransactionError(string errorText)
        {
            if(this.TransactionError != null){
                this.TransactionError(this,new EventArgs());
            }
        }

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ivar Lumi
Estonia Estonia
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 20 Apr 2007
Article Copyright 2007 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid