Author Topic: The requested address is not valid in its context.  (Read 6082 times)

Leslie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 17
    • View Profile
The requested address is not valid in its context.
« on: December 04, 2014, 07:13:13 AM »
What does this mean? "The requested address is not valid in its context."
I keep getting this warning.

When I try to start a game server it instantly fails (as if not even attempting to connect) with my error message "Failed to connect to Lobby Server" and I can see on my lobby side that nothing connected to it. I made sure the IP is correct.

  1. protected void Start()
  2. {
  3.         if (Application.isPlaying)
  4.         {
  5.                 TNet.Tools.ResolveIPs(null);
  6.                 Screen.sleepTimeout = SleepTimeout.NeverSleep;
  7.  
  8.                 lobby = gameObject.AddComponent<TNTcpLobbyClient>();
  9.                 lobby.remoteAddress = "x.x.x.x";
  10.                 lobby.remotePort = 5129;
  11.         }
  12. }
  13.  
  14. ....
  15. if (TNServerInstance.Start(GamePort, 0, null, TNServerInstance.Type.Tcp, TNet.Tools.ResolveEndPoint("x.x.x.x:5129")))
  16. {
  17.         if (TNServerInstance.lobby != null)
  18.         {
  19.                 if (TNServerInstance.lobby.isActive)
  20.                 {
  21.                         TNManager.Connect("127.0.0.1", GamePort);
  22.                         return;
  23.                 }
  24.         }
  25.  
  26.         CloseConnection();
  27.         DestroySession();
  28.         BattlemassUI.Instance.ShowMessage("Error", "Failed to connect to Lobby Server.", BattlemassUI.Icon_Warning, "close");
  29. }
  30. else
  31. {
  32.         DestroySession();
  33.         BattlemassUI.Instance.ShowMessage("Error", "Error while trying to start game server.", BattlemassUI.Icon_Warning, "close");
  34. }
  35.  

This is the lobby server output ...

  1. root@game:~/lobbyserver# mono TNServer.exe -tcpLobby 5129
  2.  
  3. Local IPs: 1
  4.   1: x.x.x.x(Primary)
  5.  
  6. Gateway IP:  None found
  7. External IP: x.x.x.x
  8.  
  9. TCP Lobby Server started on port 5129
  10. Press 'q' followed by ENTER when you want to quit.
  11.  
  12. UPnP discovery failed. TNet won't be able to open ports automatically.
  13.  

I did check with nmap and the ports seems to be open.
« Last Edit: December 04, 2014, 10:07:42 AM by Leslie »

Leslie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 17
    • View Profile
Re: The requested address is not valid in its context.
« Reply #1 on: December 04, 2014, 10:25:49 AM »
I see what I did wrong on the game server side. The registration with Lobby server is only done once TNManager.Connect is called. I still want to know what the warning means though cause it just keep popping up in the unity console continuously while the TNTcpLobbyClient component is active.

  1. The requested address is not valid in its context.
  2.  
  3. UnityEngine.Debug:LogWarning(Object)
  4. TNTcpLobbyClient:Update() (at Assets/TNet/Client/TNTcpLobbyClient.cs:96)
  5.  
« Last Edit: December 04, 2014, 01:46:33 PM by Leslie »

Leslie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 17
    • View Profile
Re: The requested address is not valid in its context.
« Reply #2 on: December 04, 2014, 02:14:50 PM »
Found the problem. You will note that I add the Component and do not have it available from the start, on the object. I guess what I need to do does not matter whether I got it on there or not cause I can't provide the correct address in the editor.

So what is happening is that TNTcpLobbyClient.OnEnable gets called, the address is empty so IPAddress.Broadcast is used and it is stuck with that. I hacke dit and made TNTcpLobbyClient.mRemoteAddress public so I can disable the component, set that variable to null and then when I enable the component again it will init correctly.

Is there allready a way to deal with this or perhaps a feature request is in order? I need a way to specify a different address for the lobby to use after Awake/Start/OnEnable.

Here is what I do now. This works for me and I can now get the list of server from a remote lobby.

  1. protected void Start()
  2. {
  3.         if (Application.isPlaying)
  4.         {
  5.                 TNet.Tools.ResolveIPs(null);
  6.                 Screen.sleepTimeout = SleepTimeout.NeverSleep;
  7.  
  8.                 LobbyAddress = plyUtil.ReadHostFile(LobbyAddress);
  9.                 lobby = gameObject.AddComponent<TNTcpLobbyClient>();
  10.                 lobby.enabled = false; // will enable it when I actually need it
  11.                 lobby.remoteAddress = LobbyAddress;
  12.                 lobby.remotePort = LobbyPort;
  13.                 (lobby as TNTcpLobbyClient).mRemoteAddress = null; // get rid of the incorrect address
  14.         }
  15. }
« Last Edit: December 04, 2014, 02:20:17 PM by Leslie »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: The requested address is not valid in its context.
« Reply #3 on: December 05, 2014, 01:11:14 AM »
The lobby client should be already present on the game object and should simply start disabled. You should enable it yourself when you actually need it.

That said, I see no reason for me to not change those OnEnable() functions to be Start() instead. I'll make it happen.

Leslie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 17
    • View Profile
Re: The requested address is not valid in its context.
« Reply #4 on: December 06, 2014, 12:19:43 PM »
Good idea. Did not think of setting it disabled in inspector. That way I do not have to set the var null.