Author Topic: UPnP discovery failed after update  (Read 5435 times)

dereklam0528

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 20
    • View Profile
UPnP discovery failed after update
« on: July 20, 2014, 08:53:53 AM »
Hello,

I created project a while ago and had been able to create a local server on mobile devices (iOS & Android), which can play game together within the same wifi network (LAN). I didn't update the TNET plugin for a while until today, but once I updated it to the latest version, the UPnP part is not working anymore. It gives the following error message when I run "TNServerInstance.Start(5127, 0, null, 5129);":

UPnP discovery failed. TNet won't be able to open ports automatically.

And the example scene also has the same message, I don't know what to do. Can someone please help me? I was going to upload a APK and ipa today, but now I have to postpone it. :'(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UPnP discovery failed after update
« Reply #1 on: July 20, 2014, 11:36:36 AM »
Sounds like you have multiple network interfaces. Hamachi, perhaps? Set the default network interface before starting the server:
  1. UdpProtocol.defaultNetworkInterface = Tools.localAddress;
  2. TNServerInstance.Start(5127, 0, null, 5129);
Also, TNet will now use multicasting rather than broadcasting by default. You can disable it using
  1. UdpProtocol.useMulticasting = false;
...prior to starting the server. However only do this if you run into any other issues.

dereklam0528

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: UPnP discovery failed after update
« Reply #2 on: July 21, 2014, 11:18:02 AM »
Thank you for your reply, it actually solves this problem. That error no longer appears on the logs. But I encounter another issue after I start the server:

"Unhandled Exception: System.Net.WebException: An error occurred performing a WebClient request. ---> System.NotSupportedException: http://icanhazip.com/
  at System.Net.WebRequest.GetCreator (System.String prefix) [0x00000] in <filename unknown>:0
  at System.Net.WebRequest.Create (System.Uri requestUri) [0x00000] in <filename unknown>:0
  at System.Net.WebClient.GetWebRequest (System.Uri address) [0x00000] in <filename unknown>:0
  at System.Net.WebClient.SetupRequest (System.Uri uri) [0x00000] in <filename unknown>:0
  at System.Net.WebClient.DownloadDataCore (System.Uri address, System.Object userToken) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Net.WebClient.DownloadDataCore (System.Uri address, System.Object userToken) [0x00000] in <filename unknown>:0
  at System.Net.WebClient.DownloadData (System.Uri address) [0x00000] in <filename unknown>:0
  at System.Net.WebClient.DownloadString (System.String address) [0x00000] in <filename unknown>:0
  at TNet.Tools.ResolveExternalIP (System.String url) [0x00000] in <filename unknown>:0
  at TNet.Tools.GetExternalAddress () [0x00000] in <filename unknown>:0
  at TNet.Tools.get_externalAddress () [0x00000] in <filename unknown>:0
  at TNet.LobbyServerLink.SendThread () [0x00000] in <filename unknown>:0"

It looks like it has something to do with the external address. But I don't know what to do.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UPnP discovery failed after update
« Reply #3 on: July 21, 2014, 04:11:31 PM »
Can't say I've seen that one, so I'd be curious to know what it's all about. You can catch it by wrapping the function in a try/catch block:
  1.         static bool ResolveExternalIP (string url)
  2.         {
  3.                 if (string.IsNullOrEmpty(url)) return false;
  4.  
  5.                 try
  6.                 {
  7.                         WebClient web = new WebClient();
  8.                         string text = web.DownloadString(url).Trim();
  9.                         string[] split1 = text.Split(':');
  10.  
  11.                         if (split1.Length >= 2)
  12.                         {
  13.                                 string[] split2 = split1[1].Trim().Split('<');
  14.                                 mExternalAddress = ResolveAddress(split2[0]);
  15.                         }
  16.                         else mExternalAddress = ResolveAddress(text);
  17.  
  18.                         if (mExternalAddress != null)
  19.                         {
  20.                                 isExternalIPReliable = true;
  21.                                 return true;
  22.                         }
  23.                 }
  24.                 catch (System.Exception) { }
  25.                 return false;
  26.         }

dereklam0528

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: UPnP discovery failed after update
« Reply #4 on: July 22, 2014, 10:22:07 AM »
Hi,

I try and catch the error and got this:

"An error occurred performing a WebClient request."

Does it help?

P.S. This is on iOS.

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UPnP discovery failed after update
« Reply #5 on: July 22, 2014, 08:00:18 PM »
Is the internet actually reachable on your device? All this does is sends an HTTP request to that address.

dereklam0528

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: UPnP discovery failed after update
« Reply #6 on: July 22, 2014, 08:03:25 PM »
Yes, I login to Facebook and get access to my Facebook username before starting the server.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UPnP discovery failed after update
« Reply #7 on: July 22, 2014, 08:09:02 PM »
Strange then. Does this only happen for that icanhazip address? Do others work? Does the external IP resolve fine? It tries a few different websites.

dereklam0528

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: UPnP discovery failed after update
« Reply #8 on: July 23, 2014, 10:08:14 AM »
Hi,

I just found it is because of the stripping level, which I previously set to Strip by ByteCode. If I put it into disable, it is working fine now. :P

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UPnP discovery failed after update
« Reply #9 on: July 23, 2014, 09:39:17 PM »
Ah yes, stripping is the devil. It removes a lot of key functionality and is not suitable for anything other than extremely simple games that don't use any plugins from my experience.