Author Topic: Unable to Host or Join Server once server Instance stopped  (Read 3130 times)

nidhi_singh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
I'M using server model based on Example Menu, Once game is finished I am sending player back to Main Menu and calling TNServerInstance.Stop("server.dat");  If I try to re-host or reconnect to already hosted server I'm unable to so.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unable to Host or Join Server once server Instance stopped
« Reply #1 on: May 05, 2015, 10:53:21 PM »
You will need to post some code. TNServerInstance.Stop is enough to stop the server, but what happens after?

nidhi_singh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Unable to Host or Join Server once server Instance stopped
« Reply #2 on: May 06, 2015, 01:51:40 AM »
For say you are playing game and went to main menu and the server is stopped, if you try to start the server again its not happening.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unable to Host or Join Server once server Instance stopped
« Reply #3 on: May 07, 2015, 09:39:08 PM »
Works fine in Windward. I can start/stop servers repeatedly. Same with the example that comes with TNet. So I re-iterate: you will need to post some code for me to be able to help you.

nidhi_singh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Unable to Host or Join Server once server Instance stopped
« Reply #4 on: May 08, 2015, 09:03:31 AM »
This Is Function for Hosting Server Its Called On Button Press The Script Is Attached To Empty Game Object With TN Manager, TN Object and TN UDPLobbyClient Script Attached.

public void OnCreateServer()
   {
      //Stating Ports For tcp Upd and LAN

         int udpPort = Random.Range(10000, 40000);
         TNLobbyClient lobby = GetComponent<TNLobbyClient>();
         
         if (lobby == null)
         {
            //TNServerInstance.Start(tcpPort,udpPort,lobbyPort,"server.dat");
            TNServerInstance.Start(serverTcpPort, udpPort, "server.dat");   
         }
         else
         {
            //Hosting Server
            mMessage = "Server started";
            TNServerInstance.Type type = (lobby is TNUdpLobbyClient) ? TNServerInstance.Type.Udp : TNServerInstance.Type.Tcp;
            TNServerInstance.Start(serverTcpPort, udpPort, lobby.remotePort, "server.dat", type);

         }
         
         TNManager.Connect (Tools.localAddress.ToString());      
   }

This Function is Called On a  In Game Button

public void OnResetTap()
   {
      BackToMenu = true;
      TNManager.Disconnect();

   }

   void OnNetworkLeaveChannel ()
   {
      TNManager.LoadLevel("GameMenu");
   }
This is Called On GameMenu
void Start()
   {
      if(MultiplayerResetScript.BackToMenu == true)
      {
         TNServerInstance.Stop("server.dat");
         MultiplayerResetScript.BackToMenu = false;
      }
   }

After This if I Try Re-Hosting Server or Try To Join to Already Hosted Server I'm unable to do so. Sorry for Long Post.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unable to Host or Join Server once server Instance stopped
« Reply #5 on: May 09, 2015, 04:33:58 AM »
You should change your OnNetworkLeaveChannel to OnNetworkDisconnect instead. You should also shut down the server when you disconnect:
  1. TNManager.Disconnect();
  2. TNServerInstance.Stop("server.dat");
That's all I do on my end that's different. Is your TNet up to date? I double-checked the TNet's examples yesterday and they work as expected, although I did have to put up 2.0.6 as I noticed I haven't released an update in a while.

P.S. Note that TNServerInstance.Start returns a boolean value that tells you whether the operation was successful. You may want to check for it before trying to connect.

nidhi_singh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Unable to Host or Join Server once server Instance stopped
« Reply #6 on: May 13, 2015, 01:10:52 AM »
Thanks for the reply, after working for hours I finally found out problem  :). I'm using NGUI buttons for my game UI. After I go back to main menu create  server function is getting removed from UIButton OnClick. If I manually attach it then its working fine. Still I have to figure out why its happening.