Easiest approach: run your server, and a headless client (Unity using TNet client). The idea is to have the headless client join the channel first -- thus becoming the host.
I generally don't advise this approach though as it's very resource-intensive (you need a new local Unity+TNet client for each channel). Having the clients handle physics is still by far the cheapest solution.
OK so in my server code, I create a static Headless Client as you suggested:
static TNet
.GameClient HeadlessClientHost
= new TNet
.GameClient();
I then do a connect to my localhost by:
IPEndPoint ip = TNet.Tools.ResolveEndPoint("127.0.0.1", 19101);
if (ip == null)
{
Debug.LogError("Unable to resolve 127.0.0.1");
}
else
{
HeadlessClientHost.playerName = "RoomServerAdmin";
NGUIDebug.Log("Connect to Server");
HeadlessClientHost.Connect(ip, null);
}
At this point I believe my client connects successfully, but now it's a matter of the event triggers that were used in TNManager. When this client connects I have:
void OnNetworkConnect(bool success, string message)
{
NGUIDebug.Log("Connected to Server");
HeadlessClientHost.JoinChannel(ServerChannelNumber, "", false, 7, "");
HeadlessClientHost.playerName = "ServerAdmin";
}
which is probably not right because the OnNetworkConnect is only used on TNManager which I'm not using.
What do I need to do to allow the TNet.GameClient to have proper OnNetworkConnect,OnNetworkJoinChannel,OnNetworkPlayerJoin,OnNetwrokPlayerLeave, etc. notifications?
Update:I add an Awake method with this:
void Awake()
{
HeadlessClientHost.onConnect = OnNetworkConnect;
}
I still do not seem to be able to get that method to fire on connect.
Thank you!