/** * 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); }
/** * Creates a listening point for the specified socket and attempts to * discover how its local address is NAT mapped. * @param socket the socket whose address needs to be resolved. * @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(MyUdpClient socket) { NetAccessPointDescriptor apDesc = stunStack.InstallNetAccessPoint(socket); requestSender = new BlockingRequestSender(stunProvider, apDesc); StunMessageEvent evt = null; try { evt = requestSender.SendRequestAndWaitForResponse( MessageFactory.CreateBindingRequest(), serverAddress); } finally { stunStack.RemoveNetAccessPoint(apDesc); } if (evt != null) { Response res = (Response)evt.GetMessage(); MappedAddressAttribute maAtt = (MappedAddressAttribute) res.GetAttribute(Attribute.MAPPED_ADDRESS); if (maAtt != null) { return(maAtt.GetAddress()); } } return(null); }
/** * Shuts down the underlying stack and prepares the object for garbage * collection. */ public virtual void ShutDown() { StunStack.ShutDown(); stunStack = null; stunProvider = null; requestSender = null; this.started = false; }
/** * 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; }
/** * Shuts down the underlying stack and prepares the object for garbage * collection. */ public virtual void ShutDown() { StunStack.ShutDown(); stunStack = null; stunProvider = null; apDescriptor = null; requestSender = null; this.started = false; }