StringToBytes() private static method

private static StringToBytes ( string str ) : byte[]
str string
return byte[]
Beispiel #1
0
        public bool Initialize()
        {
            bool result;

            if (this.m_BroadcastData.Length >= 1024)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkDiscovery Initialize - data too large. max is " + 1024);
                }
                result = false;
            }
            else
            {
                if (!NetworkTransport.IsStarted)
                {
                    NetworkTransport.Init();
                }
                if (this.m_UseNetworkManager && NetworkManager.singleton != null)
                {
                    this.m_BroadcastData = string.Concat(new object[]
                    {
                        "NetworkManager:",
                        NetworkManager.singleton.networkAddress,
                        ":",
                        NetworkManager.singleton.networkPort
                    });
                    if (LogFilter.logInfo)
                    {
                        Debug.Log("NetworkDiscovery set broadcast data to:" + this.m_BroadcastData);
                    }
                }
                this.m_MsgOutBuffer       = NetworkDiscovery.StringToBytes(this.m_BroadcastData);
                this.m_MsgInBuffer        = new byte[1024];
                this.m_BroadcastsReceived = new Dictionary <string, NetworkBroadcastResult>();
                ConnectionConfig connectionConfig = new ConnectionConfig();
                connectionConfig.AddChannel(QosType.Unreliable);
                this.m_DefaultTopology = new HostTopology(connectionConfig, 1);
                if (this.m_IsServer)
                {
                    this.StartAsServer();
                }
                if (this.m_IsClient)
                {
                    this.StartAsClient();
                }
                result = true;
            }
            return(result);
        }
        /// <summary>
        ///   <para>Initializes the NetworkDiscovery component.</para>
        /// </summary>
        /// <returns>
        ///   <para>Return true if the network port was available.</para>
        /// </returns>
        public bool Initialize()
        {
            if (this.m_BroadcastData.Length >= 1024)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError((object)("NetworkDiscovery Initialize - data too large. max is " + (object)1024));
                }
                return(false);
            }
            if (!NetworkTransport.IsStarted)
            {
                NetworkTransport.Init();
            }
            if (this.m_UseNetworkManager && (UnityEngine.Object)NetworkManager.singleton != (UnityEngine.Object)null)
            {
                this.m_BroadcastData = "NetworkManager:" + NetworkManager.singleton.networkAddress + ":" + (object)NetworkManager.singleton.networkPort;
                if (LogFilter.logInfo)
                {
                    Debug.Log((object)("NetwrokDiscovery set broadbast data to:" + this.m_BroadcastData));
                }
            }
            this.m_MsgOutBuffer       = NetworkDiscovery.StringToBytes(this.m_BroadcastData);
            this.m_MsgInBuffer        = new byte[1024];
            this.m_BroadcastsReceived = new Dictionary <string, NetworkBroadcastResult>();
            ConnectionConfig defaultConfig = new ConnectionConfig();
            int num = (int)defaultConfig.AddChannel(QosType.Unreliable);

            this.m_DefaultTopology = new HostTopology(defaultConfig, 1);
            if (this.m_IsServer)
            {
                this.StartAsServer();
            }
            if (this.m_IsClient)
            {
                this.StartAsClient();
            }
            return(true);
        }