/// <overloads>
 /// Initializes a new instance of the <see cref="BluetoothListener"/> class.
 /// </overloads>
 /// ----
 /// <summary>
 /// Initializes a new instance of the <see cref="BluetoothListener"/> class
 /// to listen on the specified service identifier.
 /// </summary>
 /// <param name="service">The Bluetooth service to listen for.</param>
 /// <remarks>
 /// <para>
 /// An SDP record is published on successful <see cref="M:InTheHand.Net.Sockets.BluetoothListener.Start"/>
 /// to advertise the server.
 /// A generic record is created, containing the essential <c>ServiceClassIdList</c>
 /// and <c>ProtocolDescriptorList</c> attributes.  The specified service identifier is
 /// inserted into the former, and the RFCOMM Channel number that the server is
 /// listening on is inserted into the latter.  See the Bluetooth SDP specification
 /// for details on the use and format of SDP records.
 /// </para><para>
 /// If a SDP record with more elements is required, then use
 /// one of the other constructors that takes an SDP record e.g. 
 /// <see cref="M:InTheHand.Net.Sockets.BluetoothListener.#ctor(System.Guid,InTheHand.Net.Bluetooth.ServiceRecord)"/>,
 /// or when passing it as a byte array 
 /// <see cref="M:InTheHand.Net.Sockets.BluetoothListener.#ctor(System.Guid,System.Byte[],System.Int32)"/>.
 /// The format of the generic record used here is shown there also.
 /// </para><para>
 /// Call the <see cref="M:InTheHand.Net.Sockets.BluetoothListener.Start"/> 
 /// method to begin listening for incoming connection attempts.
 /// </para>
 /// </remarks>
 public BluetoothListener(Guid service)
 {
     InitServiceRecord(service);
     this.serverEP = new BluetoothEndPoint(BluetoothAddress.None, service);
     serverSocket = new Socket(AddressFamily32.Bluetooth, SocketType.Stream, BluetoothProtocolType.RFComm);
     m_optionHelper = new BluetoothClient.SocketOptionHelper(serverSocket);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="BluetoothListener"/> class
        /// with the specified local endpoint.
		/// </summary>
        /// <param name="localEP">A <see cref="BluetoothEndPoint"/> that represents the local endpoint to which to bind the listener <see cref="Socket"/>.</param>
        /// <remarks>
        /// <para>
        /// An SDP record is published on successful <see cref="M:InTheHand.Net.Sockets.BluetoothListener.Start"/>
        /// to advertise the server.
        /// A generic record is created, containing the essential <c>ServiceClassIdList</c>
        /// and <c>ProtocolDescriptorList</c> attributes.  The specified service identifier is
        /// inserted into the former, and the RFCOMM Channel number that the server is
        /// listening on is inserted into the latter.  See the Bluetooth SDP specification
        /// for details on the use and format of SDP records.
        /// </para><para>
        /// If a SDP record with more elements is required, then use
        /// one of the other constructors that takes an SDP record e.g. 
        /// <see cref="M:InTheHand.Net.Sockets.BluetoothListener.#ctor(InTheHand.Net.BluetoothEndPoint,InTheHand.Net.Bluetooth.ServiceRecord)"/>,
        /// or when passing it as a byte array
        /// <see cref="M:InTheHand.Net.Sockets.BluetoothListener.#ctor(InTheHand.Net.BluetoothEndPoint,System.Byte[],System.Int32)"/>.
        /// The format of the generic record used here is shown there also.
        /// </para><para>
        /// Call the <see cref="M:InTheHand.Net.Sockets.BluetoothListener.Start"/> 
        /// method to begin listening for incoming connection attempts.
        /// </para>
        /// </remarks>
        public BluetoothListener(BluetoothEndPoint localEP)
		{
            if (localEP == null)
            {
                throw new ArgumentNullException("localEP");
            }

            InitServiceRecord(localEP.Service);
            this.serverEP = localEP;
            serverSocket = new Socket(AddressFamily32.Bluetooth, SocketType.Stream, BluetoothProtocolType.RFComm);
            m_optionHelper = new BluetoothClient.SocketOptionHelper(serverSocket);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BluetoothListener"/> class
        /// that listens for incoming connection attempts on the specified local Bluetooth address and service identifier. 
        /// </summary>
        /// <param name="localaddr">A <see cref="BluetoothAddress"/> that represents the local Bluetooth radio address.</param>
        /// <param name="service">The Bluetooth service on which to listen for incoming connection attempts.</param>
        /// <remarks>
        /// <para>
        /// An SDP record is published on successful <see cref="M:InTheHand.Net.Sockets.BluetoothListener.Start"/>
        /// to advertise the server.
        /// A generic record is created, containing the essential <c>ServiceClassIdList</c>
        /// and <c>ProtocolDescriptorList</c> attributes.  The specified service identifier is
        /// inserted into the former, and the RFCOMM Channel number that the server is
        /// listening on is inserted into the latter.  See the Bluetooth SDP specification
        /// for details on the use and format of SDP records.
        /// </para><para>
        /// If a SDP record with more elements is required, then use
        /// one of the other constructors that takes an SDP record e.g. 
        /// <see cref="M:InTheHand.Net.Sockets.BluetoothListener.#ctor(InTheHand.Net.BluetoothAddress,System.Guid,InTheHand.Net.Bluetooth.ServiceRecord)"/>,
        /// or when passing it as a byte array, e.g. 
        /// <see cref="M:InTheHand.Net.Sockets.BluetoothListener.#ctor(InTheHand.Net.BluetoothAddress,System.Guid,System.Byte[],System.Int32)"/>.
        /// The format of the generic record used here is shown there also.
        /// </para><para>
        /// Call the <see cref="M:InTheHand.Net.Sockets.BluetoothListener.Start"/> 
        /// method to begin listening for incoming connection attempts.
        /// </para>
        /// </remarks>
        public BluetoothListener(BluetoothAddress localaddr, Guid service)
        {
            if (localaddr == null) {
                throw new ArgumentNullException("localaddr");
            }
            if (service == Guid.Empty) {
                throw new ArgumentNullException("service");
            }

            InitServiceRecord(service);
            this.serverEP = new BluetoothEndPoint(localaddr, service);
            serverSocket = new Socket(AddressFamily32.Bluetooth, SocketType.Stream, BluetoothProtocolType.RFComm);
            m_optionHelper = new BluetoothClient.SocketOptionHelper(serverSocket);
        }