Esempio n. 1
0
        /**
         * Creates a listening point from the following address and attempts to
         * discover how it is mapped so that using inside the application is possible.
         * @param address the [address]:[port] pair where ther request should be
         * sent from.
         * @return a StunAddress object containing the mapped address or null if
         * discovery failed.
         * @throws StunException if something fails along the way.
         */
        public virtual StunAddress GetMappingFor(StunAddress address)
        {
            NetAccessPointDescriptor apDesc = new NetAccessPointDescriptor(address);

            stunStack.InstallNetAccessPoint(apDesc);

            requestSender = new BlockingRequestSender(stunProvider, apDesc);
            StunMessageEvent evt = null;

            try
            {
                evt = requestSender.SendRequestAndWaitForResponse(
                    MessageFactory.CreateBindingRequest(), serverAddress);
            }
            finally
            {
                //free the port to allow the application to use it.
                stunStack.RemoveNetAccessPoint(apDesc);
            }

            if (evt != null)
            {
                Response res = (Response)evt.GetMessage();
                MappedAddressAttribute maAtt =
                    (MappedAddressAttribute)
                    res.GetAttribute(Attribute.MAPPED_ADDRESS);
                if (maAtt != null)
                {
                    StunAddress sa = maAtt.GetAddress();
                    return(sa);
                }
            }

            return(null);
        }
        /**
         * Puts the discoverer into an operational state.
         * @throws StunException if we fail to bind or some other error occurs.
         */
        virtual public void Start()
        {
            stunStack = StunStack.Instance;
            stunStack.Start();

            stunStack.InstallNetAccessPoint(apDescriptor);

            stunProvider = stunStack.GetProvider();

            requestSender = new BlockingRequestSender(stunProvider, apDescriptor);

            started = true;
        }
        /**
         * Puts the discoverer into an operational state.
         * @throws StunException if we fail to bind or some other error occurs.
         */
        public virtual void Start()
        {
            stunStack = StunStack.Instance;
            stunStack.Start();

            stunStack.InstallNetAccessPoint(apDescriptor);

            stunProvider = stunStack.GetProvider();

            requestSender = new BlockingRequestSender(stunProvider, apDescriptor);

            started = true;
        }