Beispiel #1
0
        /*
         * public STUN( int ourport, GotExternalAddress callback )
         * {
         *  LogFile.WriteLine( "STUN( ourport: " + ourport + " callback: " + callback.Target + "." + callback.Method.Name );
         *
         *  INetworkImplementation level1net = NetworkImplementationFactory.CreateNewInstance();
         *  level1net.ConnectAsClient( new IPAddress( stunser ), serverinfo.port
         *
         *  UdpClient udpclient = new UdpClient( StunServerHostname, StunServerPort );
         *  byte[] bytes = CreateSTUNBindingRequestPacket();
         *  udpclient.Send( bytes, bytes.Length );
         * }
         */
        byte[] CreateSTUNBindingRequestPacket()
        {
            Request request = MessageFactory.CreateBindingRequest();
            ChangeRequestAttribute changeRequest = (ChangeRequestAttribute)request.GetAttribute(net.voxx.stun4cs.Attribute.CHANGE_REQUEST);

            changeRequest.SetChangeIpFlag(false);
            changeRequest.SetChangePortFlag(false);

            TransactionID transactionID = TransactionID.CreateTransactionID();

            request.SetTransactionID(transactionID.GetTransactionID());

            byte[] bytes = request.Encode();
            return(bytes);
        }
        /**
         * Creates a client transaction
         * @param providerCallback the provider that created us.
         * @param request the request that we are living for.
         * @param requestDestination the destination of the request.
         * @param apDescriptor the access point through which we are supposed to
         * @param responseCollector the instance that should receive this request's
         * response.
         * retransmit.
         */
        public StunClientTransaction(StunProvider            providerCallback,
			Request                  request,
			StunAddress              requestDestination,
			NetAccessPointDescriptor apDescriptor,
			ResponseCollector        responseCollector)
        {
            this.providerCallback  = providerCallback;
            this.request           = request;
            this.apDescriptor      = apDescriptor;
            this.responseCollector = responseCollector;
            this.requestDestination = requestDestination;

            this.transactionID = TransactionID.CreateTransactionID();

            request.SetTransactionID(transactionID.GetTransactionID());

            runningThread = new Thread(new ThreadStart(this.Run));
        }