Author Topic: Starting New Server in Game  (Read 13702 times)

destructicorn

  • Guest
Starting New Server in Game
« on: July 01, 2013, 11:57:23 AM »
In my game the server is hosted locally on one player's computer and shut down once the match is over.  I'm having an issue with restarting/starting a new server.  Anytime I try and restart/start a new server I get a "VerifyResponseID expected ResponseID, got Disconnect" warning.  I start the server via TNServerInstance.start(), then in OnNetworkConnect I have the player join a channel and proceed to the next scene.  Upon end of game, I have the host LeaveChannel and then disconnect before calling TNServerInstace.Stop().  I'm not sure what I'm doing wrong.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Starting New Server in Game
« Reply #1 on: July 01, 2013, 08:56:15 PM »
TNServerInstance.Stop() should be all you need, but keep in mind the effect is not immediate. Closing ports on the firewall may take a few seconds.

ConfluxGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Starting New Server in Game
« Reply #2 on: June 14, 2014, 11:51:40 AM »
Bringing this thread back up because I have a similar issue with a little different end result.  Same situation, game instances will need to stop and start servers from within the game.  Then they will need to disconnect, stop the server and either start another one or join another one.

I had the same issue, when I used TNManager.Disconnect() and TNServerInstance.Stop(), then when I tried to use TNServerInstance.Start() It returned "Connect - false, expected a response ID, but go ERROR"

So I switched to just TNServerInstance.Stop() and that error stopped, however, now when I start the server for the second time TNManager.isHosting is false! Any thoughts?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Starting New Server in Game
« Reply #3 on: June 15, 2014, 06:21:12 AM »
TNManager.isHosting tells you whether you are the channel's host. Do you actually connect to the server afterwards and join the channel? Is there anyone else in the channel?

ConfluxGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Starting New Server in Game
« Reply #4 on: June 15, 2014, 10:31:13 AM »
I do connect to the server, but not the channel yet.  In the connect response is where I need to check if I am "running" the server or not.  The first attempt, "isHosting" correctly tells me if I have started the server or not (for both sides, whether it was created or not").  But as soon as I stop the server apparently isHosting is no longer reliable until I join another channel.  Is there a better way for me to determine "isHosting" at this point (on connection response).  perhaps TNServerInstance.isActive or something?

ConfluxGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Starting New Server in Game
« Reply #5 on: June 15, 2014, 10:56:35 AM »
Just tested a little more thoroughly.  And it appears the original error still is occurring.  TNServerInstance.start()  TNServerInstance.stop() (I even waited like 20 seconds here)  TNServerInstance.start is throwing "Expected a ResponseID, but got ERROR". 

An interesting note: the server is still created and I am able to connect!  however, I cannot join a channel (even if I am the first one to join).  It just sits there and get no OnJoinChannel response, no errors are thrown.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Starting New Server in Game
« Reply #6 on: June 16, 2014, 09:26:28 AM »
TNManager.isHosting is telling you if you are a host of a channel. If you are not yet in a channel, then this should remain 'false'.

This has nothing in common with you running a server. That's not the same as being a host. Host is just another player -- basically the channel's moderator. There can only be one host per channel.

The error you're getting is likely because you don't wait for the operation to complete. TNManager.Disconnect() sends a packet to the server, but if the server is stopped, that packet will never arrive. You need to do it in steps: TNManager.Disconnect, wait for OnNetworkDisconnect, and then shut down the server.

ConfluxGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Starting New Server in Game
« Reply #7 on: June 16, 2014, 10:17:04 AM »
Ok I put TNManager.Disconnect().  wait for OnNetworkDisconnect, and call TNServerInstance.Stop().  I then waited a minute (just to give the server enough time to shut down if that was the case) then try to to start the and connect.  Still get the same error.

To be thorough, I also tried this - in the OnNetworkDisconnect, after I call TNServerInstance.Stop(), I also Destroy(GameObject.Find("_Server"));  So when the TNServerInstance.start() is called again it creates a new server from scratch... still throws the error.

ConfluxGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Starting New Server in Game
« Reply #8 on: June 16, 2014, 02:18:32 PM »
One thing I also just noticed is, if I reload the scene after using TNServerInstance.Stop()  everything works as it should (can start and stop server at will)  but if the scene is not reloaded, that is when I get that error message.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Starting New Server in Game
« Reply #9 on: June 17, 2014, 02:22:29 PM »
Well, try as hard as I could, I was not able to reproduce this with TNet's example scenes. I can start and stop the server many times over, and connection works as expected each time. Have you tried debugging to see what the error packet is?

P.S. I just realized I may be on an updated version of TNet however... when was the last time I pushed an update? Hmm... I should do that now.

bloodwalker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Starting New Server in Game
« Reply #10 on: September 17, 2014, 08:19:59 PM »
Hello.

I am having a similar problem. One of the players creates a server for LAN only and other players can connect easily just once. However, when the player that creates the server disconnects and closes server while in game (other players quit first) and goes back to the first scene where the server can be created again, I cannot create it, I get a message like this

192.168.1.10:5127 timeout

Another option was to keep the server in a static variable in a game object that is never destroyed, since the player is going to host many times, and stopping starting on and off didn't seem normal, I disconnect and go back to the first scene and then I can't connect. I don't get an error message... it just stays trying to connect
« Last Edit: September 17, 2014, 08:26:36 PM by bloodwalker »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Starting New Server in Game
« Reply #11 on: September 18, 2014, 05:32:20 PM »
How do you stop the server? Do you call TNServerInstance.Stop()?

bloodwalker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Starting New Server in Game
« Reply #12 on: September 19, 2014, 06:16:07 PM »
We are not using TNServerInstance but a script that creates a GameServer for LAN only and manages connections to it.

When we create and destroy, we use the Stop() method and wait for full disconnections to go to a scene where it gets created. When it tries to get created again either I get a timeout or it gets created but no one can connect. 

When we keep our own GameServer Static, we simply disconnect so it can be reused again. The server listens to connections, but we can't connect.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Starting New Server in Game
« Reply #13 on: September 19, 2014, 10:09:21 PM »
Well if you created your own game server, then I can't help you much. The issue is somewhere in it so, how can help? Look at what TNServerInstance does that you don't. That's about all I can suggest.

bloodwalker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Starting New Server in Game
« Reply #14 on: September 23, 2014, 07:30:43 PM »
Hello.

We changed to TNServerInstance and it works fine on Editor, but when used on iOS the game crashes just on stopping the server

we call first TNManaget.Disconnect() and wait for OnNetworkDisconnect() event to trigger to call TNServerInstance.Stop(). Right on that line. The game crashes.

  1. public void OnNetworkDisconnect()
  2. {
  3.      Debug.Log("Before Stop");
  4.      TNServerInstance.Stop();
  5.      Debug.Log("After Stop"); //This line never shows up when the app on iOS crashes
  6. }
  7.  
« Last Edit: September 23, 2014, 09:06:26 PM by bloodwalker »