Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: Nagransham on May 01, 2014, 04:01:49 AM

Title: Direct connection via ip
Post by: Nagransham on May 01, 2014, 04:01:49 AM
Hey guys. Let me start by saying that I'm rather new to this whole networking thing. That is to say that i know how to insert the cable and that's about it ;)

Now, this is what i want to achieve:
Say you start the game, click on a button and thereby host a game. Now i want another player, who happens to know my ip, to be able to join me.

However i can't get it to work. And I'm not sure why that is. It works just fine with two instaces of the game and even hamachi/tunngle are working just fine. However i can't get a direct connection to work. Now i wonder if this has something to do with some problem with my connection (or the one I'd try to connect to for that matter) or if I'm doing something wrong in the code.

This is essentially all i do:

  1. TNServerInstance.Start(5127);
  2. TNManager.Connect(ip + ":5127");
  3.  
  4.     void OnNetworkConnect(bool success, string message)
  5.     {
  6.         connectionText.text = message;
  7.         TNManager.JoinChannel(1, "Game"); // Obviously this is not all that useful if the connection doesn't work out, but i'm lazy.
  8.     }
  9.  

As i said, it works fine for local connections but when i try this online all i get is "unable to connect".

So... is this somehow local only ? Is my code way off ? Or is it some network shenanigans i know nothing about ? And if it indeed has something to do with port forwading or what ever, am i an exception, or would every player have to mess around with their router in order to connect ?

Thanks in advance :)
Title: Re: Direct connection via ip
Post by: ArenMook on May 02, 2014, 09:46:45 AM
TNServerInstance.Start should only be executed on one computer -- the computer you are actually starting the server on. Everyone else should be connecting to it. You can also launch TNServer.exe instead of starting a TNServerInstance. When connecting, you need to specify the external IP address of the computer where you launched the server. The server must be accessible from the outside -- with appropriate port(s) open.
Title: Re: Direct connection via ip
Post by: Nagransham on May 02, 2014, 09:54:37 AM
Yep already figured it out. Forwarded the ports in question and everything works great now.

Oh and, i actually am starting the server on one computer only, i just figured there is no need to post unity interface code :P

Thanks anyway :)