Author Topic: How to connect to the Tnetserver.exe from anywhere around the world?  (Read 4610 times)

speedyw03

  • Guest
When I run TNetServer.exe on my computer, I can connect to the "server" by TNManager.Connect(X);
the x is the internal IP adress.
Everything works!
So I sent over a build to a friend and he can't connect..
I'm a little bit confused here, the tnetserver shows 3 IP adresses, only the internal works (only for me)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to connect to the Tnetserver.exe from anywhere around the world?
« Reply #1 on: March 09, 2013, 04:06:48 PM »
Internal address is (obviously) for internal use only. Outside people need to use your external address, and either UPnP must be functional, or you must open up ports on your router.

speedyw03

  • Guest
Re: How to connect to the Tnetserver.exe from anywhere around the world?
« Reply #2 on: March 09, 2013, 04:19:56 PM »
When I use external IP I get: Could not make a connection because the target machine actively refused it. btw my computer is swedish so I used google translate to translate the debug message.

I logged into my router and UPnP was enabled


« Last Edit: March 09, 2013, 04:33:33 PM by speedyw03 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to connect to the Tnetserver.exe from anywhere around the world?
« Reply #3 on: March 09, 2013, 09:11:37 PM »
That checkbox is grayed out, so it's unclear if it's actually functional or not.

Running TNServer.exe will tell you if the gateway is accessible or not. You won't see a gateway IP if it's not.

speedyw03

  • Guest
Re: How to connect to the Tnetserver.exe from anywhere around the world?
« Reply #4 on: March 10, 2013, 07:06:56 AM »
This is what I get:


And here's my menu code:
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Net;
  5. using TNet;
  6.  
  7. public class cTest : MonoBehaviour {
  8.         public string conso;
  9.         public string adress;
  10.         public string port;
  11.         public GameObject player;
  12.         public int games;
  13.  
  14.         public int[] pCount = new int[10];
  15.        
  16.         // Use this for initialization
  17.         void Start () {
  18.                 /*if(Application.isPlaying){
  19.                         TNManager.StartUDP(Random.Range(100,50000));
  20.                 }*/
  21.                 InvokeRepeating("Refresh",2,2);
  22.         }
  23.        
  24.         // Update is called once per frame
  25.         void Update () {
  26.        
  27.         }
  28.         void OnGUI(){
  29.                 GUILayout.Label("Connection status: " +TNManager.isConnected);
  30.                 adress = GUILayout.TextField(adress);
  31.                 port = GUILayout.TextField(port);
  32.                 //This is where I connect
  33.                 if(GUILayout.Button("Connect"+conso)){
  34.                         TNManager.Connect(adress,int.Parse(port));
  35.                 }
  36.                 if(GUILayout.Button("Join Channel")){
  37.                         TNManager.JoinChannel(1,"game");
  38.                 }
  39.                 if(TNManager.isConnected){
  40.                         if(TNManager.isInChannel){
  41.                                 if(GUILayout.Button("Destroy")){
  42.                                         GameObject[] g;
  43.                                         g = GameObject.FindGameObjectsWithTag("Player");
  44.                                         for(int s = 0; s< g.Length; s++){
  45.                                                 TNManager.Destroy(g[s]);
  46.                                         }
  47.                                 }
  48.                                 if(GUILayout.Button("Spawn")){
  49.                                         TNManager.Create(player);
  50.                                 }
  51.                         }
  52.                         if(GUILayout.Button("Get Channel List")){
  53.                                 TNManager.client.BeginSend(Packet.RequestChannelList);
  54.                                 TNManager.client.EndSend();
  55.                         }
  56.                         if(GUILayout.Button("Join Channel2")){
  57.                                 TNManager.JoinChannel(2,"game");
  58.                         }
  59.                         GUILayout.BeginArea(new Rect(Screen.width/2,0,Screen.width/2,Screen.height));
  60.                                 for(int g=0;g<games;g++){
  61.                                         GUILayout.BeginHorizontal();
  62.                                         if(GUILayout.Button("Game: "+(g+1))){
  63.                                                 TNManager.JoinChannel(g+1,"game");
  64.                                         }
  65.                                         GUILayout.Label("Players: "+pCount[g]);
  66.                                         GUILayout.EndHorizontal();
  67.                                 }
  68.                         GUILayout.EndArea();
  69.                         if(TNManager.isInChannel){
  70.                                 if(GUILayout.Button("Leave Channel")){
  71.                                         TNManager.LeaveChannel();
  72.                                         Application.LoadLevel("menu");
  73.                                 }
  74.                         }
  75.                 }
  76.                 /*if(GUILayout.Button("Get Channel List")){
  77.  
  78.                 }*/
  79.         }
  80.         void OnNetworkConnect (bool success, string message) {
  81.                 print(success+ message);
  82.                 conso=""+success;
  83.                 TNManager.client.packetHandlers[(byte)Packet.ResponseChannelList] = OnChannelList;
  84.         }
  85.         void OnNetworkError (string message){
  86.                 conso = message;
  87.         }
  88.         void OnNetworkJoinChannel (bool success,string message){
  89.                 conso = message;
  90.                 print ("Joined channel");
  91.                 TNManager.Create(player);
  92.         }
  93.        
  94.         //#############################
  95.         void OnChannelList (Packet response, BinaryReader reader, IPEndPoint source)
  96.         {
  97.             int count = reader.ReadInt32();
  98.                 //System.Array.Resize(ref pCount, 0);
  99.             for (int i = 0; i < count; ++i)
  100.             {
  101.                 int channelID           = reader.ReadInt32();
  102.                 int playerCount         = reader.ReadInt32();
  103.                 bool password           = reader.ReadBoolean();
  104.                 bool isPersistent       = reader.ReadBoolean();
  105.                 string level            = reader.ReadString();
  106.                         //conso = playerCount+" "+level+" " +channelID;
  107.                         games = count;
  108.                         System.Array.Resize(ref pCount, count);
  109.                         pCount[i] = playerCount;
  110.                         print("channel ID: "+channelID+" Player Count: "+playerCount+" level: "+ level);
  111.             }
  112.         }
  113.         void Refresh(){
  114.                 TNManager.client.BeginSend(Packet.RequestChannelList);
  115.                 TNManager.client.EndSend();
  116.         }
  117.        
  118. }
I've tried to connect to all three ports (5127, 5128 & 5129) and using the external address, but I still can't connect

When I posted the screenshot of UPnP I wasn't logged in as admin, now that I've checked it enabled

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to connect to the Tnetserver.exe from anywhere around the world?
« Reply #5 on: March 11, 2013, 09:02:23 AM »
Not all routers allow you to connect using an external address. Your gateway is functional and ports get opened fine, which means people will be able to connect to you from the outside.

This is why TNet uses both by default. It will try to connect to an external address first, and when that fails -- to an internal one. That's how the server discovery works (it sends both).