Author Topic: Unity freezes sometimes when using some disconnect code from TNet  (Read 2078 times)

troglodescu

  • Guest
When I quit the main game scene where a server is active and the player is connected, I want to make sure that it disconnects and the server is also shut down so no-one can connect to an unplayable server.

I use the code bellow every time I quit the game scene.

  1. public static void StopNetworkActivity()
  2.     {
  3.         TNManager.Disconnect();
  4.         TNManager.CloseChannel();
  5.         if (TNServerInstance.isActive)
  6.         {
  7.             TNServerInstance.Stop();
  8.         }
  9.     }
  10.  

When connected with another player, it sometimes freezes the whole thing, on any platform (iOS, android, PC or Unity Editor)

Am I doing something wrong by misusing the code above or is it something from TNet or .Net itself ?

Anyone else experienced freezing due to TNet code ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity freezes sometimes when using some disconnect code from TNet
« Reply #1 on: July 04, 2013, 09:19:38 AM »
Why do you close channels after disconnecting?

TNManager.Disconnect();
TNServerInstance.Stop();

...is all you need.

Keep in mind, if the server opened ports with your router, it will need to close them -- a process that may take a few seconds.

troglodescu

  • Guest
Re: Unity freezes sometimes when using some disconnect code from TNet
« Reply #2 on: July 04, 2013, 09:59:57 AM »
Thanks for the quick reply :)

So you think the freezing might take place because I was unnecessarily closing the channel as well ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity freezes sometimes when using some disconnect code from TNet
« Reply #3 on: July 04, 2013, 04:52:59 PM »
No, most likely it happens because when you shut down the server, TNet has to close the opened ports on the router.