예제 #1
0
        public void Transact(TransactionFunc transactionFunc)
        {
            bool initialCall = false;

            if (transaction == null)
            {
                initialCall = true;
                transaction = new Transaction(this);
                transactionCleanups.Add(transaction);
            }
            try
            {
                transactionFunc(transaction);
            }
            finally
            {
                if (initialCall && transactionCleanups[0] == transaction)
                {
                    CleanupTransactions();
                }
            }
        }
예제 #2
0
 void updateTransaction()
 {
     var lMessage = transaction.continueTransaction();
     if (lMessage != null || transaction.overTime)
     {
         transactionFunc = transactionFunc(lMessage);
     }
 }
예제 #3
0
    /// <summary>
    /// Gets NAT info from STUN server.
    /// </summary>
    /// <param name="host">STUN server name or IP.</param>
    /// <param name="port">STUN server port. Default port is 3478.</param>
    /// <param name="socket">UDP socket to use.</param>
    /// <returns>Returns UDP netwrok info.</returns>
    /// <exception cref="Exception">Throws exception if unexpected error happens.</exception>
    public void Query(string host, int port, Socket socket)
    {
        if (host == null)
        {
            throw new System.ArgumentNullException("host");
        }
        if (socket == null)
        {
            throw new System.ArgumentNullException("socket");
        }
        if (port < 1)
        {
            throw new System.ArgumentNullException("Port value must be >= 1 !");
        }
        if (socket.ProtocolType != ProtocolType.Udp)
        {
            throw new System.ArgumentNullException("Socket must be UDP socket !");
        }

        IPEndPoint remoteEndPoint = new IPEndPoint(System.Net.Dns.GetHostAddresses(host)[0], port);

        socket.ReceiveTimeout = 3000;
        socket.SendTimeout = 3000;

        // Test I
        STUN_Message test1 = new STUN_Message();
        test1.Type = STUN_MessageType.BindingRequest;
        transaction.doTransaction(test1, socket, remoteEndPoint);
        transactionFunc = test1ResponeFunc;
        timer.enabled = true;
    }
예제 #4
0
 TransactionFunc transactionRespone(STUN_Message pRequest,TransactionFunc pFunc )
 {
     transaction.doTransaction(pRequest);
     return pFunc;
 }