public static NetWorker Host(ushort port, TransportationProtocolType comType, int maxConnections, bool winRT = false, string overrideIP = null, bool allowWebplayerConnection = false, bool relayToAll = true, bool useNat = false, NetWorker.NetworkErrorEvent errorCallback = null)
{
Threading.ThreadManagement.Initialize();
Unity.MainThreadManager.Create();
if (Sockets == null) Sockets = new Dictionary<ushort, NetWorker>();
if (Sockets.ContainsKey(port) && Sockets[port].Connected)
throw new NetworkException(8, "Socket has already been initialized on that port");
if (comType == TransportationProtocolType.UDP)
Sockets.Add(port, new CrossPlatformUDP(true, maxConnections));
else
{
if (winRT)
Sockets.Add(port, new WinMobileServer(maxConnections));
else
{
Sockets.Add(port, new DefaultServerTCP(maxConnections));
((DefaultServerTCP)Sockets[port]).RelayToAll = relayToAll;
}
}
// JM: added error callback in args in case Connect() below fails
if (errorCallback != null) {
Sockets [port].error += errorCallback;
}
Sockets[port].connected += delegate()
{
Sockets[port].AssignUniqueId(0);
if (connectedInvoker != null)
connectedInvoker(Sockets[port]);
};
Sockets[port].UseNatHolePunch = useNat;
Sockets[port].Connect(overrideIP, port);
#if !NETFX_CORE
// TODO: Allow user to pass in the variables needed to pass into this begin function
if (allowWebplayerConnection)
SocketPolicyServer.Begin();
#endif
SimpleNetworkedMonoBehavior.Initialize(Sockets[port]);
return Sockets[port];
}