/** * Called to notify this provider for an incoming message. * @param event the event object that contains the new message. */ public virtual void HandleMessageEvent(StunMessageEvent @event) { Message msg = @event.GetMessage(); //request if (msg is Request) { TransactionID serverTid = TransactionID. CreateTransactionID(msg.GetTransactionID()); serverTransactions.Add(serverTid); if (requestListener != null) { requestListener.requestReceived(@event); } } //response else if (msg is Response) { TransactionID tid = TransactionID. CreateTransactionID(msg.GetTransactionID()); StunClientTransaction tran = (StunClientTransaction)clientTransactions[tid]; clientTransactions.Remove(tid); if (tran != null) { tran.HandleResponse(@event); } else { //do nothing - just drop the phantom response. } } }
/** * Sends the specified request through the specified access point, and * registers the specified ResponseCollector for later notification. * @param request the request to send * @param sendTo the destination address of the request. * @param sendThrough the access point to use when sending the request * @param collector the instance to notify when a response arrives or the * the transaction timeouts * @throws StunException * ILLEGAL_STATE if the stun stack is not started. <br/> * ILLEGAL_ARGUMENT if the apDescriptor references an access point that had * not been installed <br/> * NETWORK_ERROR if an error occurs while sending message bytes through the * network socket. <br/> * */ public virtual void SendRequest(Request request, StunAddress sendTo, NetAccessPointDescriptor sendThrough, ResponseCollector collector) { stunStack.CheckStarted(); StunClientTransaction clientTransaction = new StunClientTransaction(this, request, sendTo, sendThrough, collector); clientTransactions[clientTransaction.GetTransactionID()] = clientTransaction; clientTransaction.SendRequest(); }
/** * Cancels all running transactions and prepares for garbage collection */ public virtual void ShutDown() { requestListener = null; ArrayList toRemove = new ArrayList(); foreach (object o in clientTransactions.Keys) { toRemove.Add(o); } foreach (TransactionID id in toRemove) { StunClientTransaction sct = (StunClientTransaction)clientTransactions[id]; clientTransactions.Remove(id); if (sct != null) { sct.Cancel(); } } }
/** * Removes a client transaction from this providers client transactions list. * Method is used by ClientStunTransaction-s themselves when a timeout occurs. * @param tran the transaction to remove. */ public void RemoveClientTransaction(StunClientTransaction tran) { clientTransactions.Remove(tran.GetTransactionID()); }
/** * Sends the specified request through the specified access point, and * registers the specified ResponseCollector for later notification. * @param request the request to send * @param sendTo the destination address of the request. * @param sendThrough the access point to use when sending the request * @param collector the instance to notify when a response arrives or the * the transaction timeouts * @throws StunException * ILLEGAL_STATE if the stun stack is not started. <br/> * ILLEGAL_ARGUMENT if the apDescriptor references an access point that had * not been installed <br/> * NETWORK_ERROR if an error occurs while sending message bytes through the * network socket. <br/> */ public virtual void SendRequest( Request request, StunAddress sendTo, NetAccessPointDescriptor sendThrough, ResponseCollector collector ) { stunStack.CheckStarted(); StunClientTransaction clientTransaction = new StunClientTransaction(this, request, sendTo, sendThrough, collector); clientTransactions[clientTransaction.GetTransactionID()] = clientTransaction; clientTransaction.SendRequest(); }