R
R
RB2015-06-01 01:40:08
C++ / C#
RB, 2015-06-01 01:40:08

Why doesn't UDP Hole Punching always bypass NAT?

This code allows you to make p2p between users, but sometimes it works every other time. Tested with a friend, everything works fine. But as soon as he tries to do the same with another user, everything stops working. Maybe different types of NAT or something.
The program itself connects to the STUN server and receives public ip. Then, when connecting through a third-party server (we use jabber text messages), we initialize and exchange ip between users. But something goes wrong

switch (data.com)
{
case "Call":
   if (MessageBox.Show("Звонок от " + msg.From.Bare, "Входящий", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
   {
   //Была нажата кнопка “Yes”
      string ipp = data.data;  //Получает ip вызывающего пользлвателя
      userEndPoint = new IPEndPoint(IPAddress.Parse(ipp.Substring(0, ipp.IndexOf(":"))),
                                    Convert.ToInt32(ipp.Substring(ipp.IndexOf(":") + 1)));
      UDPMess(); //Отправляем ему UDP пакет
      To = msg.From;
      SentTo(Command.Yes, myEndPoint, msg.From); //Сообщаем серверу что мы ожидаем пользователя и свой ip
      StartVoice(); //Начинаем передачу голоса
   }
   else
   {
      SentTo(Command.No, null, msg.From); //Сообщаем серверу об отказе
   }
   break;
case "Yes":
   //Происходит, если пользователь согласился на передачу и ожидает отклика
   //Все тоже самое только для инициирующей передачу стороны
   string ip = data.data;
   userEndPoint = new IPEndPoint(IPAddress.Parse(ip.Substring(0, ip.IndexOf(":"))),
                                Convert.ToInt32(ip.Substring(ip.IndexOf(":") + 1)));
   UDPMess();
   To = msg.From;
   StartVoice();
   MessageBox.Show("Пользователь " + msg.From.Bare + " принял вызов");
   break;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Pukhov, 2015-06-01
@Neuroware

As far as I remember, there is a so-called symmetric NAT, and Hole Punching does not work through it. And so if in 1 case it works, then the only thing that can interfere in another is the provider or firewall

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question