BeardedManStudios.Network.Networking.Host C# (CSharp) Method

Host() public static method

Will setup a new server on this machine
public static Host ( ushort port, TransportationProtocolType comType, int maxConnections, bool winRT = false, string overrideIP = null, bool allowWebplayerConnection = false, bool relayToAll = true, bool useNat = false, BeardedManStudios.Network.NetWorker errorCallback = null ) : BeardedManStudios.Network.NetWorker
port ushort This is the port you want to bind the server to
comType TransportationProtocolType The particular transportation protocol you wish to be used for this server
maxConnections int The maximum connections (players) allowed on the server at one point in time
winRT bool If this is Windows Phone or Windows Store, this should be true, otherwise default to false
overrideIP string
allowWebplayerConnection bool Allow web player connections to server
relayToAll bool Used to determine if messages should be relayed to client (normally true) - Mainly internal
useNat bool
errorCallback BeardedManStudios.Network.NetWorker
return BeardedManStudios.Network.NetWorker
		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];
		}