public static NetWorker Connect(string ip, ushort port, TransportationProtocolType comType, bool winRT = false, bool useNat = false, bool standAlone = false)
{
Threading.ThreadManagement.Initialize();
Unity.MainThreadManager.Create();
if (Sockets == null) Sockets = new Dictionary<ushort, NetWorker>();
if (Sockets.ContainsKey(port))
{
#if UNITY_IOS || UNITY_IPHONE
if (comType == TransportationProtocolType.UDP)
Sockets[port] = new CrossPlatformUDP(false, 0);
else
Sockets[port] = new DefaultClientTCP();
#else
if (Sockets[port].Connected)
throw new NetworkException(8, "Socket has already been initialized on that port");
else if (Sockets[port].Disconnected)
Sockets.Remove(port);
else
return Sockets[port]; // It has not finished connecting yet
#endif
}
else if (comType == TransportationProtocolType.UDP)
Sockets.Add(port, new CrossPlatformUDP(false, 0));
else
{
if (winRT)
Sockets.Add(port, new WinMobileClient());
else
Sockets.Add(port, new DefaultClientTCP());
}
Sockets[port].connected += delegate()
{
if (connectedInvoker != null)
connectedInvoker(Sockets[port]);
};
Sockets[port].UseNatHolePunch = useNat;
Sockets[port].Connect(ip, port);
if (!standAlone)
SimpleNetworkedMonoBehavior.Initialize(Sockets[port]);
return Sockets[port];
}