/** * 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); }
/** * Start the network listening thread. * * @throws IOException if we fail to setup the socket. */ public virtual void Start() { //do not create the socket earlier as someone might want to set an existing one // was != null fixed (Ranga) if (sock == null) { try { IPEndPoint ipe = new IPEndPoint(GetDescriptor().GetAddress(). GetSocketAddress().GetAddress(), GetDescriptor().GetAddress(). GetSocketAddress().GetPort()); this.sock = new MyUdpClient(ipe); } catch (SocketException se) { Console.WriteLine("{0} {1}", se.Message, se.StackTrace); return; } this.isUsingExternalSocket = false; } // sock.setReceiveBufferSize(MAX_DATAGRAM_SIZE); this.isRunning = true; Thread thread = new Thread(new ThreadStart(this.Run)); thread.Name = "NetAccessPoint: " + this.sock.GetAddress() + ":" + this.sock.GetPort(); thread.Start(); }
/** * Creates and starts a new access point based on the specified socket. * If the specified access point has already been installed the method * has no effect. * * @param socket the socket that the access point should use. * @return an access point descriptor to allow further management of the * newly created access point. * @throws StunException if we fail to create or start the accesspoint. */ public NetAccessPointDescriptor InstallNetAccessPoint(MyUdpClient socket) { //no null check - let it through a null pointer exception StunAddress address = new StunAddress(socket.GetAddress().ToString(), socket.GetPort()); NetAccessPointDescriptor apDescriptor = new NetAccessPointDescriptor(address); if (netAccessPoints.ContainsKey(apDescriptor)) { return(apDescriptor); } NetAccessPoint ap = new NetAccessPoint(apDescriptor, messageQueue, this); //call the useExternalSocket method to avoid closing the socket when //removing the accesspoint. Bug Report - Dave Stuart - SipQuest ap.UseExternalSocket(socket); netAccessPoints[apDescriptor] = (ap); ap.Start(); return(apDescriptor); }
/** * Creates and starts the specified Network Access Point based on the specified * socket and returns a relevant descriptor. * * @param sock The socket that the new access point should represent. * @throws StunException * <p>NETWORK_ERROR if we fail to create or bind the datagram socket.</p> * <p>ILLEGAL_STATE if the stack had not been started.</p> * @return a descriptor of the newly created access point. */ public virtual NetAccessPointDescriptor InstallNetAccessPoint(MyUdpClient sock) { CheckStarted(); return(netAccessManager.InstallNetAccessPoint(sock)); }
/** * Creates and starts a new access point based on the specified socket. * If the specified access point has already been installed the method * has no effect. * * @param socket the socket that the access point should use. * @return an access point descriptor to allow further management of the * newly created access point. * @throws StunException if we fail to create or start the accesspoint. */ public NetAccessPointDescriptor InstallNetAccessPoint(MyUdpClient socket) { //no null check - let it through a null pointer exception StunAddress address = new StunAddress(socket.GetAddress().ToString(), socket.GetPort()); NetAccessPointDescriptor apDescriptor = new NetAccessPointDescriptor(address); if(netAccessPoints.ContainsKey(apDescriptor)) return apDescriptor; NetAccessPoint ap = new NetAccessPoint(apDescriptor, messageQueue, this); //call the useExternalSocket method to avoid closing the socket when //removing the accesspoint. Bug Report - Dave Stuart - SipQuest ap.UseExternalSocket(socket); netAccessPoints[apDescriptor] = (ap); ap.Start(); return apDescriptor; }
/** * Sets a socket for the access point to use. This socket will not be closed * when the AP is <code>stop()</code>ed (Bug Report - Dave Stuart - SipQuest). * @param socket the socket that the AP should use. */ public void UseExternalSocket(MyUdpClient socket) { this.sock = socket; this.isUsingExternalSocket = true; }
/** * Start the network listening thread. * * @throws IOException if we fail to setup the socket. */ public virtual void Start() { //do not create the socket earlier as someone might want to set an existing one // was != null fixed (Ranga) if(sock == null) { try { IPEndPoint ipe = new IPEndPoint(GetDescriptor().GetAddress(). GetSocketAddress().GetAddress(), GetDescriptor().GetAddress(). GetSocketAddress().GetPort()); this.sock = new MyUdpClient(ipe); } catch (SocketException se) { Console.WriteLine("{0} {1}", se.Message, se.StackTrace); return; } this.isUsingExternalSocket = false; } // sock.setReceiveBufferSize(MAX_DATAGRAM_SIZE); this.isRunning = true; Thread thread = new Thread(new ThreadStart(this.Run)); thread.Name = "NetAccessPoint: "+this.sock.GetAddress()+":"+this.sock.GetPort(); thread.Start(); }
/** * Sets a socket for the access point to use. This socket will not be closed * when the AP is <code>stop()</code>ed (Bug Report - Dave Stuart - SipQuest). * @param socket the socket that the AP should use. */ public void UseExternalSocket(MyUdpClient socket) { this.sock = socket; this.isUsingExternalSocket = true; }
/** * Creates and starts the specified Network Access Point based on the specified * socket and returns a relevant descriptor. * * @param sock The socket that the new access point should represent. * @throws StunException * <p>NETWORK_ERROR if we fail to create or bind the datagram socket.</p> * <p>ILLEGAL_STATE if the stack had not been started.</p> * @return a descriptor of the newly created access point. */ public virtual NetAccessPointDescriptor InstallNetAccessPoint(MyUdpClient sock) { CheckStarted(); return netAccessManager.InstallNetAccessPoint(sock); }