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:
public void HostServerTest (GameObject Button)
{
/*mUPnP.Start();
mUPnP.WaitForThreads();*/
mUPnP.OpenUDP(5127, OnPortOpened);
TNServerInstance.Start(5127, 0, "server.dat");
TNManager.Connect("73.6.215.102:5127");
}
To this:
public void HostServerTest ()
{
TNServerInstance.Start(5127, 0, "server.dat");
}
/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:
public void OnClick(string sender)
{
if (sender == "btnStartServer")
{
TNServerInstance.Start (28001, 0, "server.dat");
TNManager.Connect("192.168.56.1:28001");
}
else if (sender == "btnJoinServer")
{
TNManager.Connect(serverAddress, serverPort);
}
}
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).