Author Topic: TNManager.ServerInstance + Connect question  (Read 4825 times)

synoptik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
TNManager.ServerInstance + Connect question
« on: July 19, 2013, 10:33:06 AM »
I'm trying to create a server in unity and to connect to it.  I juste modded the AutoConnect script as follow ...

  1. void Start ()
  2.         {
  3.                 if (connectOnStart)
  4.                 {
  5.                         if(isInstructeur)
  6.                         {
  7.                                
  8.                                 TNServerInstance.Start(5127,5128, "server.dat",TNServerInstance.Type.Udp, Tools.ResolveEndPoint("127.0.0.1", 5129));
  9.                                
  10.                         }else{
  11.                                
  12.                                 Connect();
  13.                                
  14.                         }
  15.                        
  16.                 }
  17.         }
  18.  
  19.  
  20.  

I replace the connectToIP variable to my local ip adress, but I can't join the game.  I think it may be a channel issue on my side but can't figure it out.  I just need that the clients joins the "game" and enter directly the same map as the server (wich the first one is always the same).  Everything happen on LAN only.  We'll start the server and then the 5 clients.

Thanks for any help !

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #1 on: July 19, 2013, 11:06:31 AM »
The command you are using starts a local server and registers it with the UDP-based lobby server located at "127.0.0.1:5129". You are not actually connecting to anything specific here, so I am not sure what it is you are trying to do. Find a server and auto join it?

synoptik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #2 on: July 19, 2013, 11:10:46 AM »
Actually my server is always the same computer.  I want to auto join to it with the 6 other computers that are in the class room.  The clients must connect and auto join ;)

pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #3 on: July 19, 2013, 01:52:28 PM »
GameServer gameServer = new GameServer();
string name = "A Server Name";
string saveFile = "savefile.dat";
int tcpPort = 5127;
int udpPort = 5128;

void Start()
{
        gameServer.name = name;
        gameServer.Start(tcpPort, udpPort);
        gameServer.LoadFrom(saveFile);

}

That should work for you, just make sure that you don't destroy on load if you load a new scene.

synoptik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #4 on: July 21, 2013, 10:31:40 AM »
I can't believe that what I want to do is that difficult.  Everything would work fine if the "instructor" station would not get disconnected after 10 seconds when I use the Server.exe file deliver with the Tnet package. 

pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #5 on: July 21, 2013, 12:29:38 PM »
You shouldn't get disconnected from the TNServer.exe.  When i first started learning TNET i was using that till i was ready to start making my own server and my son would be playing the game i had made for an hour or more at a time with his friend and never get disconnected.  Make sure that the objects with your connections to the server are not getting destroyed, and that your variables that hold the connection stay alive. If they are only in a method, when the method finishes you will loose the connection.

synoptik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #6 on: July 21, 2013, 03:02:34 PM »
Object destroyed.  That would make sense cause only the computer that start as an instructor gets disconnected after 10 seconds.  All others are ok.  I'll take a look at this this evenig when my kids are back with their mom.  Thanks !

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #7 on: July 22, 2013, 04:29:46 AM »
Most common cause of 10 sec disconnects is forgetting to check "run in background" and alt tabbing to some other application.

synoptik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #8 on: July 22, 2013, 06:51:50 AM »
The "run in background" checkbox is checked.  In fact I'm using the same built for the instructor and the students.  They choose to draw the instructor interface or to spawn an ambulance from a config file.  The instructor stays connected to the TNserver as long as their no other computers connected.  When I connect another computer, the instructor disconnect after 10 seconds.  Here's what I got in the TNAutoCreate script :

  1. if(isInstructeur == "true")
  2.                 {
  3.                        
  4.                         TNManager.Create(instructeur, spawnInstructeur.transform.position, spawnInstructeur.transform.rotation, persistent);
  5.                         camInstructeur.SetActive(true);
  6.                         Destroy(gameObject);
  7.                        
  8.                        
  9.  
  10.                 }else{
  11.                        
  12.                         if(SimID == "Poste 1")
  13.                         {
  14.                                 TNManager.Create(poste1, parking1.transform.position, parking1.transform.rotation, persistent);
  15.                                 Destroy(gameObject);
  16.                         }
  17.                         if(SimID == "Poste 2")
  18.                         {
  19.                                 TNManager.Create(poste2, parking2.transform.position, parking2.transform.rotation, persistent);
  20.                                 Destroy(gameObject);
  21.                         }

I tried with and without the "Destroy(gameObject);" line for each object.  The clients (poste1, poste2, poste3) and the instructor (instructeur) are referenced in the inspector as objects in the TNManager script public variables.

Thanks for your time guys.

synoptik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #9 on: July 22, 2013, 07:54:20 AM »
Another detail I just saw, my clients always connect with a port around 49000 and the instructor connects with a port around 1500.  Dunno if that can help.

EDIT : Also, when I try to connect as a client from the instructor computer I get disconnected.  My ambulance spawn in a parking correctly but I'm on my own, can't see the other clients.  The difference between the instructor and the clients is that the instructor only have a overview camera and an interface that allows him to follow any clients. 

So the problem look to come from the computer :  I'm "hosting" the TNServer on the same computer that the instructor.  This is the computer that keep having problems.

That's why I tried to create a server instance inside Unity.  But when I try the code psycho2day give me, I cannot find the other clients anymore.  I'll try to be clear : To follow the clients, I change the target of the Camera follow script by using this code :

  1. // Make the first button. If it is pressed, follow the poste 1
  2.                         if(GUI.Button(new Rect(20,40,180,20), "Poste 1"))
  3.                         {
  4.                                 camInstructeur.GetComponent<SmoothFollow>().target = GameObject.Find ("AmbulanceUnit1(Clone)").transform;
  5.                                
  6.                         }

Works like a charm when using TNServer.exe and staying connected long enough :P

2nd EDIT : I tried to put the TNServer.exe on another computer.  My instructor computer stays connected if I run it as a client (with an ambulance running), but time out if I connect it as an instructor.  The instructor prefab has only an Instructor Gameobject ( with the TNObject component and the Gameplayer script) and a camera.  The script above is written in the GamePlayer script.
« Last Edit: July 22, 2013, 08:56:56 AM by synoptik »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #10 on: July 22, 2013, 08:52:30 AM »
There is nothing in TNet itself that would cause someone to get disconnected when another user connects. Did you try debugging it on the server side and printing which packets you're getting? Maybe you are sending so many packets that it's causing issues?

Also I assume you have one server running, and others connect to it, not have servers running on each client?

synoptik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #11 on: July 22, 2013, 09:06:02 AM »
Well when I start the instructor in the editor, it stays connected but I have thousands of instances of these 3 errors :

Exception has been thrown by the target of an invocation.
TNAutoSync.OnSync (UnityEngine.Quaternion, UnityEngine.Vector3)


Exception has been thrown by the target of an invocation.
TNAutoSync.OnSync (UnityEngine.Quaternion)


Exception has been thrown by the target of an invocation.
TNAutoSync.OnSync (UnityEngine.Vector3, UnityEngine.Quaternion)

Wich I assume to be the auto-synchronization that I'm using to synch the position and the rotation of my ambulances.

synoptik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: TNManager.ServerInstance + Connect question
« Reply #12 on: July 22, 2013, 09:15:56 AM »
I removed the autosynch from the ambulances and from their wheels and now it stays connected.   PROGRESS !  Guess they were sending to many packets.  Will try to write [RFC]s to update the movement like you suggested in one of your videos.
« Last Edit: July 22, 2013, 09:22:14 AM by synoptik »