Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version
Go to top

STUN Client

, 20 Apr 2007
STUN client C# implementation with sample application
Stun.zip
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
Settings.settings
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Security.Cryptography.X509Certificates;

namespace LumiSoft.Net
{
    /// <summary>
    /// Holds socket bind info.
    /// </summary>
    public class BindInfo
    {
        private BindInfoProtocol m_Protocol     = BindInfoProtocol.TCP;
        private IPAddress        m_pIP          = null;
        private int              m_Port         = 0;
        private bool             m_SSL          = false;
        private X509Certificate  m_pCertificate = null;
        private object           m_Tag          = null;

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="protocol">Bind protocol.</param>
        /// <param name="ip">IP address to listen.</param>
        /// <param name="port">Port to listen.</param>
        public BindInfo(BindInfoProtocol protocol,IPAddress ip,int port)
        {
            m_Protocol = protocol;
            m_pIP      = ip;
            m_Port     = port;
        }

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="ip">IP address to listen.</param>
        /// <param name="port">Port to listen.</param>
        /// <param name="ssl">Specifies if dedicated SSL connection. If true, SSL connection negotiation 
        /// is done at once after connection is accepted.</param>
        /// <param name="sslCertificate">Certificate to use for SSL connections.</param>
        public BindInfo(IPAddress ip,int port,bool ssl,X509Certificate sslCertificate)
        {
            m_pIP          = ip;
            m_Port         = port;
            m_SSL          = ssl;
            m_pCertificate = sslCertificate;
        }


        #region override method Equals

        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>Returns true if two objects are equal.</returns>
        public override bool Equals(object obj)
        {
            if(obj == null){
                return false;
            }
            if(!(obj is BindInfo)){
                return false;
            }

            BindInfo bInfo = (BindInfo)obj;
            if(bInfo.Protocol != m_Protocol){
                return false;
            }
            if(!bInfo.IP.Equals(m_pIP)){
                return false;
            }
            if(bInfo.Port != m_Port){
                return false;
            }
            if(bInfo.SSL != m_SSL){
                return false;
            }
            if(!X509Certificate.Equals(bInfo.SSL_Certificate,m_pCertificate)){
                return false;
            }

            return true;
        }

        #endregion

        #region override method GetHashCode

        /// <summary>
        /// Returns the hash code.
        /// </summary>
        /// <returns>Returns the hash code.</returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        #endregion


        #region Properties Implementation

        /// <summary>
        /// Gets protocol.
        /// </summary>
        public BindInfoProtocol Protocol
        {
            get{ return m_Protocol; }
        }

        /// <summary>
        /// Gets IP address.
        /// </summary>
        public IPAddress IP
        {
            get{ return m_pIP; }
        }

        /// <summary>
        /// Gets port.
        /// </summary>
        public int Port
        {
            get{ return m_Port; }
        }

        /// <summary>
        /// Gets if dedicated SSL connection.
        /// </summary>
        public bool SSL
        {
            get{ return m_SSL; }
        }

        /// <summary>
        /// Gets SSL certificate.
        /// </summary>
        public X509Certificate SSL_Certificate
        {
            get{ return m_pCertificate; }
        }

        /// <summary>
        /// Gets or sets user data. This is used internally don't use it !!!.
        /// </summary>
        public object Tag
        {
            get{ return m_Tag; }

            set{ m_Tag = value; }
        }

        #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

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