Gwupe.Communication.P2P.P2P.Tunnel.Waver.Wave C# (CSharp) Method

Wave() public method

public Wave ( IPEndPoint facilitatorIp, int timeout, UdpClient udpClient ) : PeerInfo
facilitatorIp System.Net.IPEndPoint
timeout int
udpClient System.Net.Sockets.UdpClient
return PeerInfo
        public PeerInfo Wave(IPEndPoint facilitatorIp, int timeout, UdpClient udpClient)
        {
            long waitTime = timeout * 10000;
            _udpClient = udpClient;
            Logger.Debug("Waving at " + facilitatorIp + " from local port " + ((IPEndPoint)udpClient.Client.LocalEndPoint).Port + " for " + timeout + "ms");
            var packet = new StandardWaveTunnelRqPacket { internalEndPoint = new IPEndPoint(IPAddress.Any, ((IPEndPoint)udpClient.Client.LocalEndPoint).Port) };
            long startTime = DateTime.Now.Ticks;
            _waveEvent.Reset();
            // Setup a listener for a wave response
            InitReceiverWaveRs();
            do
            {
                byte[] sendBytes = packet.getBytes();
                udpClient.Send(sendBytes, sendBytes.Length, facilitatorIp);
                if (DateTime.Now.Ticks - startTime > waitTime)
                {
                    Logger.Error("Wave timeout : " + (DateTime.Now.Ticks - startTime));
                    //throw new TimeoutException("Timeout occured while waving");
                    break;
                }
                Logger.Debug("Waiting for wave response from " + facilitatorIp + " to local port " + ((IPEndPoint)udpClient.Client.LocalEndPoint).Port);
            } while (!_waveEvent.WaitOne(2000));
            if(_waveResult == null)
            {
                _waveResult = new PeerInfo();
            }
            _waveResult.InternalEndPoints = GetLocalEndPoints(_udpClient);
            return _waveResult;
        }

Usage Example

Ejemplo n.º 1
0
 public PeerInfo Wave(IPEndPoint facilitator)
 {
     var waver = new Waver();
     _self = waver.Wave(facilitator, 10000, _udpClient);
     Logger.Debug("After wave, local endpoints are " + _self);
     if (_self.ExternalEndPoint == null)
     {
         Logger.Warn("Failed to get external endpoint : " + _self);
     }
     if (_self.EndPoints.Count == 0)
     {
         throw new Exception("Failed to determine any local endpoints : " + _self.ToString());
     }
     return _self;
 }
All Usage Examples Of Gwupe.Communication.P2P.P2P.Tunnel.Waver::Wave