Init() public static method

Initializes the NetworkTransport. Should be called before any other operations on the NetworkTransport are done.

public static Init ( ) : void
return void
コード例 #1
0
        public override void Init()
        {
            if (NetworkManager.Get().enableLogging)
            {
                Debug.Log("Unet init called");
            }
            messageBuffer = new byte[MessageBufferSize];

            Unet.Init();
        }
コード例 #2
0
        public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
        {
            InitializeSingleton();

            matchInfo = info;
            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }

            isNetworkActive = true;

            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }

            client = new NetworkClient();

            if (config != null)
            {
                if ((config.UsePlatformSpecificProtocols) && (UnityEngine.Application.platform != RuntimePlatform.PS4))
                {
                    throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                }

                client.Configure(config, 1);
            }
            else
            {
                if (m_CustomConfig && m_ConnectionConfig != null)
                {
                    m_ConnectionConfig.Channels.Clear();
                    foreach (var c in m_Channels)
                    {
                        m_ConnectionConfig.AddChannel(c);
                    }
                    if ((m_ConnectionConfig.UsePlatformSpecificProtocols) && (UnityEngine.Application.platform != RuntimePlatform.PS4))
                    {
                        throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                    }
                    client.Configure(m_ConnectionConfig, m_MaxConnections);
                }
            }

            RegisterClientMessages(client);
            if (matchInfo != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient match: " + matchInfo);
                }
                client.Connect(matchInfo);
            }
            else if (m_EndPoint != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient using provided SecureTunnel");
                }
                client.Connect(m_EndPoint);
            }
            else
            {
                if (string.IsNullOrEmpty(m_NetworkAddress))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Must set the Network Address field in the manager");
                    }
                    return(null);
                }
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient address:" + m_NetworkAddress + " port:" + m_NetworkPort);
                }

                if (m_UseSimulator)
                {
                    client.ConnectWithSimulator(m_NetworkAddress, m_NetworkPort, m_SimulatedLatency, m_PacketLossPercentage);
                }
                else
                {
                    client.Connect(m_NetworkAddress, m_NetworkPort);
                }
            }

#if ENABLE_UNET_HOST_MIGRATION
            if (m_MigrationManager != null)
            {
                m_MigrationManager.Initialize(client, matchInfo);
            }
#endif

            OnStartClient(client);
            s_Address = m_NetworkAddress;
            return(client);
        }
コード例 #3
0
        bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
        {
            InitializeSingleton();

            OnStartServer();

            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }

            NetworkCRC.scriptCRCCheck   = scriptCRCCheck;
            NetworkServer.useWebSockets = m_UseWebSockets;

            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }

            // passing a config overrides setting the connectionConfig property
            if (m_CustomConfig && m_ConnectionConfig != null && config == null)
            {
                m_ConnectionConfig.Channels.Clear();
                foreach (var c in m_Channels)
                {
                    m_ConnectionConfig.AddChannel(c);
                }
                NetworkServer.Configure(m_ConnectionConfig, m_MaxConnections);
            }

            if (config != null)
            {
                NetworkServer.Configure(config, maxConnections);
            }

            if (info != null)
            {
                if (!NetworkServer.Listen(info, m_NetworkPort))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("StartServer listen failed.");
                    }
                    return(false);
                }
            }
            else
            {
                if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress))
                {
                    if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort))
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("StartServer listen on " + m_ServerBindAddress + " failed.");
                        }
                        return(false);
                    }
                }
                else
                {
                    if (!NetworkServer.Listen(m_NetworkPort))
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("StartServer listen failed.");
                        }
                        return(false);
                    }
                }
            }

            // this must be after Listen(), since that registers the default message handlers
            RegisterServerMessages();

            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkManager StartServer port:" + m_NetworkPort);
            }
            isNetworkActive = true;

            // Only change scene if the requested online scene is not blank, and is not already loaded
            string loadedSceneName = SceneManager.GetSceneAt(0).name;

            if (m_OnlineScene != "" && m_OnlineScene != loadedSceneName && m_OnlineScene != m_OfflineScene)
            {
                ServerChangeScene(m_OnlineScene);
            }
            else
            {
                NetworkServer.SpawnObjects();
            }
            return(true);
        }
コード例 #4
0
        public NetworkClient StartClient(ConnectionConfig config, int hostPort)
        {
            InitializeSingleton();

            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }

            isNetworkActive = true;

            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }

            client          = new NetworkClient();
            client.hostPort = hostPort;

            if (config != null)
            {
                if ((config.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2))
                {
                    throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                }

                client.Configure(config, 1);
            }
            else
            {
                if (m_CustomConfig && m_ConnectionConfig != null)
                {
                    m_ConnectionConfig.Channels.Clear();
                    for (int i = 0; i < m_Channels.Count; i++)
                    {
                        m_ConnectionConfig.AddChannel(m_Channels[i]);
                    }
                    if ((m_ConnectionConfig.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2))
                    {
                        throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                    }
                    client.Configure(m_ConnectionConfig, m_MaxConnections);
                }
            }

            RegisterClientMessages(client);
            if (m_EndPoint != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient using provided SecureTunnel");
                }
                client.Connect(m_EndPoint);
            }
            else
            {
                if (string.IsNullOrEmpty(m_NetworkAddress))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Must set the Network Address field in the manager");
                    }
                    return(null);
                }
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient address:" + m_NetworkAddress + " port:" + m_NetworkPort);
                }

                client.Connect(m_NetworkAddress, m_NetworkPort);
            }

            OnStartClient(client);
            s_Address = m_NetworkAddress;
            return(client);
        }
コード例 #5
0
 public void Init()
 {
     NetworkTransport.Init();
 }
コード例 #6
0
 public void Init(GlobalConfig config)
 {
     NetworkTransport.Init(config);
 }
コード例 #7
0
        private bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
        {
            InitializeSingleton();
            OnStartServer();
            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }
            NetworkCRC.scriptCRCCheck   = scriptCRCCheck;
            NetworkServer.useWebSockets = m_UseWebSockets;
            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }
            if (m_CustomConfig && m_ConnectionConfig != null && config == null)
            {
                m_ConnectionConfig.Channels.Clear();
                for (int i = 0; i < m_Channels.Count; i++)
                {
                    m_ConnectionConfig.AddChannel(m_Channels[i]);
                }
                NetworkServer.Configure(m_ConnectionConfig, m_MaxConnections);
            }
            if (config != null)
            {
                NetworkServer.Configure(config, maxConnections);
            }
            if (info != null)
            {
                if (!NetworkServer.Listen(info, m_NetworkPort))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("StartServer listen failed.");
                    }
                    return(false);
                }
            }
            else if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress))
            {
                if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("StartServer listen on " + m_ServerBindAddress + " failed.");
                    }
                    return(false);
                }
            }
            else if (!NetworkServer.Listen(m_NetworkPort))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("StartServer listen failed.");
                }
                return(false);
            }
            RegisterServerMessages();
            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkManager StartServer port:" + m_NetworkPort);
            }
            isNetworkActive = true;
            string name = SceneManager.GetSceneAt(0).name;

            if (!string.IsNullOrEmpty(m_OnlineScene) && m_OnlineScene != name && m_OnlineScene != m_OfflineScene)
            {
                ServerChangeScene(m_OnlineScene);
            }
            else
            {
                NetworkServer.SpawnObjects();
            }
            return(true);
        }