Author Topic: TNet is very troubling (furious)  (Read 7535 times)

blueagardq15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
TNet is very troubling (furious)
« on: July 28, 2015, 11:40:44 PM »
Hello, I bought TNet so I can convert my whole project to Tnet coding from Photon, and I did. My issue with TNet is There is no full explanation, and not enough tutorials/info to read off of. I have kept searching through the forum and found some answers for my other problem, I dont understand why I cannot Connect simply to a server after it is created. I wasted about 3 full days of my time to develop before my due date, and ran into so many issue and encounters. I heard very good things about TNet, but I really am not seeing it. I have been coding networking for about 2 Years and this is the most complicated Networking Solution.
---------------------------------------------------------------------
This is what I use to create a server.
  1. public void HostServerTest (GameObject Button)
  2.         {
  3.                 mUPnP = new UPnP();
  4.                 /*mUPnP.Start();
  5.                 mUPnP.WaitForThreads();*/
  6.                 mUPnP.OpenUDP(5127, OnPortOpened);
  7.                 TNServerInstance.Start(5127, 0, "server.dat");
  8.                 TNManager.Connect("73.6.215.102:5127");
  9.         }

This is what I use to connect to the server
  1. for (int i = 0; i < TNUdpLobbyClient.knownServers.list.Count; i++)
  2.                          {
  3.                         GameObject newButton = Instantiate(PlayerButton) as GameObject;
  4.                         ButtonAcess button = newButton.GetComponent<ButtonAcess>();
  5.                         //ServerListButton SLB = newButton.GetComponent<ServerListButton>();
  6.                         newButton.transform.SetParent(UIParent,false);
  7.                         //newButton.GetComponent<ButtonAcess>().PlayerAmount = PhotonNetwork.();
  8.                         //                      newButton.GetComponent<ButtonAcess>().GameName = PhotonNetwork.GetRoomList();
  9.                         //newButton.GetComponent<ButtonAcess>().Pingint = PhotonNetwork.GetPing();
  10.                         //newButton.GetComponent<ButtonAcess>().MatchName = PhotonNetwork.;
  11.                         button.button.onClick = thingToDo;
  12.                         if(button.isPressed == true)
  13.                         {
  14.                                 //TNManager.Connect(ent.internalAddress, ent.internalAddress);
  15.                         }
  16.                                 //Destroy(hostList[i].gameObject);
  17.                          }
P.S. TNUdpLobbyClient is on a gameobject already!
It does not work right, and all I get is a warning that says : An existing connection was forcibly closed by the remote host.

I looked this error up already and no solutions. Very unsatisfied with TNet as it has cost me my hours.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: TNet is very troubling (furious)
« Reply #1 on: July 29, 2015, 04:22:24 PM »
Tnet comes with full source code. No information is being kept from you. While it's not always feasible to go through the full source code due to time constraints, a brief glance is more than enough to get a sense of how it works. Moreso, if you're encountering an error message you can search through the code and find exactly where the error is thrown, and then trace it back up to see where the problem (and solution) is.

The error message you posted is a socket exception. I'm not sure which C# Type, but I am sure MSDN knows. A big part of programming is encountering errors, tracing that error, researching why that error occurs, and finally fixing that error.

I've been watching your recent threads and it seems to me that you're just copy-pasting without really understanding what you're doing. Regardless of how great tnet support is, I don't think anyone will hold your hand and write all your networking code for you.

I think exactly 100% of the questions you've asked can be answered by going through the supplied demo scenes and viewing the associated code.

Furthermore, thorough documentation does exist: http://www.tasharen.com/tnet/docs/index.html

PS: typed on a phone, I apologize for typos or poor formatting.

Edit:
Tl;dr PEBKAC.
« Last Edit: July 29, 2015, 04:32:31 PM by cmifwdll »

blueagardq15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: TNet is very troubling (furious)
« Reply #2 on: July 29, 2015, 04:59:04 PM »
 I converted all my code from photon to Tnet. I need assistance I bought something and I need support from it I don't need nobody to code network for me cause I am a programmer of unity with a team of 4. I am the leader it just put me off when you that I'm not going to have ppl code for me as its not like that I just need help understanding a networking code that I bought and I have everything setup except connect to server

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: TNet is very troubling (furious)
« Reply #3 on: July 29, 2015, 05:14:47 PM »
cmifwdll is correct.

check out the examples included with TNet.  watch the youtube videos by Aren.  read the forums - stickies are your friend.

TNet is not for the faint of heart...  but once you understand the core foundation - its pretty simple stuff.

TNet is an awesome package.  the DataNode class alone is worth the license cost.





ps  i will agree though - documentation is confusing, usually out of date and near worthless.

blueagardq15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: TNet is very troubling (furious)
« Reply #4 on: July 29, 2015, 05:47:41 PM »
Thanks, that is the type of response I am looking for :)

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: TNet is very troubling (furious)
« Reply #5 on: July 29, 2015, 08:35:48 PM »
Hello, I read your post so I can try to help, and I did. My issue with your post is that it lacks information making it difficult to pinpoint the exact issue. I have kept searching through TNet's code and found a possible solution to your problem. I believe I understand why you can't connect to your server (oh so many reasons). I wasted about 10 full minutes of my time to search for a possible solution for you. You tell me very good things about yourself, but I really am not seeing it. I have been coding networking (and englishing) for about 2 years and I'm really happy with TNet as a networking solution because it allows me to modify it to suit my needs.

Here's what I *think* you need to do (I'll make it easy to copy-paste):
Change this:
  1. public void HostServerTest (GameObject Button)
  2.     {
  3.         mUPnP = new UPnP();
  4.         /*mUPnP.Start();
  5.         mUPnP.WaitForThreads();*/
  6.         mUPnP.OpenUDP(5127, OnPortOpened);
  7.         TNServerInstance.Start(5127, 0, "server.dat");
  8.         TNManager.Connect("73.6.215.102:5127");
  9.     }
  10.  

To this:
  1. public void HostServerTest ()
  2.     {
  3.         TNServerInstance.Start(5127, 0, "server.dat");
  4.     }
  5.  

/end snarky reply

Seriously though, I'm assuming two things: 1. You are uncommenting the line TNManager.Connect in your second code snippet when you test. 2. You are launching the server and trying to connect using the button from your second code snippet in the same game instance. If this is the case, then the changes I posted could fix the error for you. If it's not the case, you're going to have to provide more information for me to help further. Where is the error coming from? Is it the TNServerInstance or the GameClient?

If it is the case and the changes I suggested do work, let me explain: You're calling TNManager.Connect in the same function you create the server, then you call TNManager.Connect a second time when you click the button (assuming you uncomment that line in your test). The TNManager.Connect function first calls Disconnect which shuts down and closes the Socket, then it goes through the connection process, opening a new Socket and connecting. This shouldn't be an issue normally, but it's possible, and it's the first thing I can think of. So, in short, there's really only need to call Connect once.

Additionally, since you aren't specifying the optional openPort parameter in your TNServerInstance.Start call, it's automatically doing the upnp stuff for you, so you can safely remove that. Unless you want additional control over the upnp stuff, in which case you need to set the optional openPort parameter to false. TNet gives you that control and that choice because it's a great networking solution.

edit:
Just tried reproducing, I was able to start and connect (twice) with the following:
  1. public void OnClick(string sender)
  2.         {
  3.                 if (sender == "btnStartServer")
  4.                 {
  5.                         TNServerInstance.Start (28001, 0, "server.dat");
  6.                         TNManager.Connect("192.168.56.1:28001");
  7.                 }
  8.                 else if (sender == "btnJoinServer")
  9.                 {
  10.                         TNManager.Connect(serverAddress, serverPort);
  11.                 }
  12.         }
  13.  
Steps: click Start Server button, wait, click Join Server button.
Result: It connects twice with no errors.
Additional Info: serverAddress variable is 192.168.56.1 and serverPort variable is 28001. Scene contains a GameObject with the TNManager component attached.

However, I noticed in your snippet your first call to Connect is using a public IP allocated to a residential ISP (comcast). Is this your WAN IP? It's very rare for routers to support hairpinning. Try switching both calls to Connect to use either loopback address (127.0.0.1) or your LAN address (eg; 192.168.1.x - you can find your LAN address many ways, ipconfig in cmd prompt, network and sharing center in win7, reading the debug log from TNManager.Awake, google). Even if it's not a router issue, it wouldn't hurt to make sure the call to Connect is using the proper IP (loopback or LAN if hosted on same machine or network, WAN if the server is hosted outside your network).
« Last Edit: July 29, 2015, 09:01:38 PM by cmifwdll »

blueagardq15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: TNet is very troubling (furious)
« Reply #6 on: July 29, 2015, 08:56:28 PM »
Thank you for taking time out to help me, and I apologize for my behavior towards you.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
TNet: Lobby Server Example
« Reply #7 on: July 30, 2015, 12:44:24 AM »
ive needed to add a lobby server for a while now.  here is the example i come up with:

please post if i've gone down the wrong path!

lobby server is on a separate machine.  this shows the remote server and the local server on the lobby list.

for my purposes, i need to connect 2 remote servers to 1 main server - 3 total.  i havent tried lobby code on the standalones yet.

  1. using UnityEngine;
  2. using TNet;
  3. using System;
  4.  
  5. public class lobbydemo : MonoBehaviour
  6. {
  7.     #region inspector set
  8.  
  9.     public GameObject prefab_button;
  10.  
  11.     #endregion
  12.  
  13.     #region GUI
  14.  
  15.     UIRoot uiroot;
  16.     UIGrid grid;
  17.     UIButton button_start;
  18.  
  19.     #endregion
  20.  
  21.     //console standalone server settings:  tcp+udp+lobby
  22.     //args = new string[] { "-name", "My Server", "-tcp", "10420", "-udp", "10421", "-tcpLobby", "10422"};
  23.  
  24.     void Awake()
  25.     {
  26.         TNTcpLobbyClient.onChange += OnChange_lobbylist;
  27.  
  28.         uiroot = GameObject.FindObjectOfType<UIRoot>();
  29.     }
  30.  
  31.     void Start()
  32.     {
  33.         grid = uiroot.transform.FindChild("grid").GetComponent<UIGrid>();
  34.         button_start = uiroot.transform.FindChild("start").GetComponent<UIButton>();
  35.  
  36.         EventDelegate del = new EventDelegate(this, "OnClick_start");
  37.         EventDelegate.Set(button_start.onClick, del);
  38.  
  39.         TNTcpLobbyClient lobby = gameObject.AddComponent<TNTcpLobbyClient>();
  40.  
  41.         lobby.remoteAddress = "192.168.2.100";
  42.         lobby.remotePort = 10422;
  43.     }
  44.    
  45.     private void OnChange_lobbylist()
  46.     {
  47.         MStorm_Helper.ClearGrid(grid);
  48.        
  49.         List<ServerList.Entry> list = TNLobbyClient.knownServers.list;
  50.        
  51.         for (int i = 0; i < list.size; ++i)
  52.         {
  53.             ServerList.Entry ent = list[i];
  54.  
  55.             Transform row = MStorm_Helper.AddRow(null, grid, prefab_button);
  56.  
  57.             string server_info = string.Format("{0} @-> {1}", ent.name, ent.internalAddress.ToString());
  58.  
  59.             row.FindChild("Label").GetComponent<UILabel>().text = server_info;
  60.  
  61.             EventDelegate del = new EventDelegate(this, "OnClick_button");
  62.             del.parameters[0].value = ent;
  63.             EventDelegate.Set(row.GetComponent<UIButton>().onClick, del);
  64.         }
  65.     }
  66.  
  67.     void OnClick_button(ServerList.Entry ent)
  68.     {
  69.         TNManager.Connect(ent.internalAddress, ent.internalAddress);
  70.     }
  71.    
  72.     void OnClick_start()
  73.     {
  74.         button_start.isEnabled = false;
  75.  
  76.         int udpPort = UnityEngine.Random.Range(10000, 40000);
  77.  
  78.         TNServerInstance.serverName = "PDX Yo!o";
  79.  
  80.         TNServerInstance.Start(5127, udpPort, null, TNServerInstance.Type.Tcp,
  81.             new System.Net.IPEndPoint(System.Net.IPAddress.Parse("192.168.2.100"), 10422));
  82.     }
  83.  
  84.     void OnNetworkConnect(bool success, string message)
  85.     {
  86.         Debug.Log(string.Format("OnNetworkConnect: success = {0} message = {1}", success, message));
  87.  
  88.         if (success)
  89.         {
  90.            
  91.         }
  92.         else
  93.         {
  94.            
  95.         }
  96.     }
  97. }
  98.  
« Last Edit: July 30, 2015, 01:06:26 AM by devomage »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet is very troubling (furious)
« Reply #8 on: July 31, 2015, 10:22:58 PM »
Quote
        mUPnP.OpenUDP(5127, OnPortOpened);
        TNServerInstance.Start(5127, 0, "server.dat");
        TNManager.Connect("73.6.215.102:5127");
1. TNServerInstance.Start uses a TCP port, not UDP. Your OpenUDP call above opens a UDP one instead.

2. When you connect, you are specifying an external address. Some routers explicitly don't allow loopback addressing (connecting to your external address from within). It's easy to check. Type 73.6.215.102 into your web browser's address. What do you see? If you see your router's welcome page, then it doesn't support loopback. You need to use 127.0.0.1 or your internal LAN address. As others have explained, open up the command prompt and use "ipconfig" to find it.

3. Unless you intend to have LAN-only discovery, UDP lobby/server discovery won't work in the long run. You need a TCP lobby. Photon = cloud based hosting, meaning you always connect to an external computer. Equivalent with TNet is to start a TNServer on a globally accessible computer, such as your own Amazon EC2 server instance. It's free to try for an entire year. This way when you connect to your server, since it's hosted on a globally accessible computer (read: your own cloud), it will "just work".

blueagardq15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: TNet is very troubling (furious)
« Reply #9 on: July 31, 2015, 11:35:30 PM »
Appreciate it :)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: TNet is very troubling (furious)
« Reply #10 on: August 13, 2015, 03:00:12 PM »
I've learnt that TNet is meant to be used the TNet way. When you understand how it works (which granted isn't anywhere near as well explained as the package is written!) it works very well and provides a very easy framework for network play. It's enabled me to work on my first network game without too much bother. But if you are coming from previous network experience, I can imagine it's throwing some conflicts with preconceptions. I've had similar, as have others from posts on this board.

I recommend staying calm and asking for support. By and large Aren is prompt with responses and they are useful. They aren't particularly verbose because he has lots of support to give and limited time! But they are on the money.

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: TNet is very troubling (furious)
« Reply #11 on: August 14, 2015, 01:42:56 PM »
I have to agree that the general idea behind this thread is an issue I have with TNet as well.

I bought TNet about 2.5 years ago (February or March, 2013, IIRC) when it was fairly new. It looked useful. It looked very powerful. But there was virtually no documentation for it. Yes, the source code is there for me to peruse, but it's a massive library and really overwhelming. Point is, I bought TNet so I wouldn't have to learn or understand how the networking works behind the scenes. I just needed an API to let me interface with the networking, and I needed documentation to teach me about the API.

But going by the quality of NGUI, and the large amount of tutorial videos for it, I figured TNet was just young and the documentation and tutorials would come in time.

I was wrong.

2.5 years later, this single page of documentation is still practically the only thing we have explaining how TNet works. There's also a video tutorial, but TNet has changed quite a bit over the years and the video quickly became outdated.

I've learnt that TNet is meant to be used the TNet way. When you understand how it works (which granted isn't anywhere near as well explained as the package is written!) it works very well and provides a very easy framework for network play.

As was pointed out by Shifty Geezer, to use TNet, you have to do things the TNet way. The problem is that the TNet way isn't really, thoroughly explained. That's my major (and perhaps only) complaint about TNet. I can tell that it's a really powerful and useful system. But the parts that it is made from aren't really explained, nor is the general concept behind the whole thing.

And looking at the source code doesn't help a whole lot at understanding the overall theory/concept of TNet. Just look at the many threads here where people don't understand the relationship between Server, Host, and Client. Imagine all the threads that would never exist (freeing up Aren's time) if there was some documentation that explains these concepts? That's just one example! What about explaining what channels are and how they work and how they should be used? The documentation page doesn't even mention DataNode, which devomage said is the best part of TNet.

TNet is an awesome package.  the DataNode class alone is worth the license cost.

In summary: I bought TNet when it was young, because I had no doubt in Aren's ability to make a great product. And when I found there was little helpful documentation, I decided to set TNet aside for a while and give Aren some time to "finish" the documentation. As I patiently waited for this, weeks became months, then months became years, and I'm still not using TNet in any projects.

Please document TNet. Explain the general concepts. Code examples are useful, but English sentences describing the overall process and the TNet way (ideal usage of TNet) would be so much more helpful.

And just to be clear: This isn't meant to be taken as derogatory toward TNet's capabilities or functionality. I'm just trying to say that TNet is a good (great?) project held back by the lack of documentation that would make it accessible to people who want to use it, and in some (many?) cases have even paid for it. I also believe it could greatly reduce the amount of time Aren has to spend providing support, as most noob questions would be explained in the documentation.