예제 #1
0
        /// <summary>
        /// 连接到指定的服务器终结点。
        /// </summary>
        /// <param name="hostname">服务地址</param>
        /// <param name="port">服务端口</param>
        /// <returns>是否连接成功</returns>
        public bool Connect(string hostname, int port)
        {
            BlazeLog.InfoFormat("[TcpClient]Connecting to {0}:{1}", hostname, port);
            if (mIsCleanedUp)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (hostname == null)
            {
                throw new ArgumentNullException("hostname");
            }
            if (!validateTcpPort(port))
            {
                throw new ArgumentOutOfRangeException("port");
            }

            try
            {
                if (mClientSocket == null)
                {
                    mClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                }
                mClientSocket.Connect(hostname, port);
                mNetworkStream = new NetworkStream(mClientSocket);
            }
            catch (Exception e)
            {
                BlazeLog.ErrorFormat("[TcpClient]Connection failed -> " + e);
                Debug.LogError("[TcpClient]Connection failed -> " + e);
                return(false);
            }
            return(true);
        }
예제 #2
0
 /// <summary>
 /// 加载指定标识符的资源。
 /// </summary>
 /// <param name="id">资源标识符</param>
 public override void Load(string id)
 {
     RaiseProgressChanged(0);
     Content = Resources.Load(id);
     if (Content == null)
     {
         BlazeLog.WarningFormat("Load content failed.id={0}", id);
     }
     RaiseProgressChanged(1);
 }
        private IEnumerator loadAsync(string id)
        {
            RaiseProgressChanged(0);
            var request = Resources.LoadAsync(id);

            while (!request.isDone)
            {
                yield return(null);

                RaiseProgressChanged(request.progress);
            }
            if (Content == null)
            {
                BlazeLog.WarningFormat("Load content failed.id={0}", id);
            }
            RaiseProgressChanged(1);
        }
예제 #4
0
        /// <summary>
        /// 获取指定路径下子物体上的组件。
        /// </summary>
        /// <typeparam name="T">组件类型</typeparam>
        /// <param name="path">路径</param>
        protected T GetChild <T>(string path) where T : Component
        {
            var child = Transform.Find(path);

            if (child == null)
            {
                BlazeLog.ErrorFormat("Can't find child '{0}' in {1}", path, GameObject.name);
                return(null);
            }
            var component = child.GetComponent <T>();

            if (component == null)
            {
                BlazeLog.ErrorFormat("Can't find component '{0}' in {1}", typeof(T).Name, GameObject.name);
                return(null);
            }
            return(component);
        }
예제 #5
0
        private IEnumerator perform(HttpRequest request)
        {
            WWW www;

            if (request.Bytes.Length == 0)
            {
                //GET
                var form = new WWWForm();
                foreach (var header in request.Headers)
                {
                    form.headers.Add(header.Key, header.Value);
                }
                if (mCookies != null)
                {
                    form.headers.Add("Cookie", mCookies);
                }
                foreach (var key in request.QueryString.Keys)
                {
                    form.AddField(key, request.QueryString[key]);
                }
                if (form.data.Length == 0)
                {
                    www = new WWW(request.Uri.ToString());
                }
                else
                {
                    www = new WWW(request.Uri.ToString(), form);
                }
            }
            else
            {
                //POST
                var headers = new Dictionary <string, string>(request.Headers);
                if (mCookies != null)
                {
                    headers.Add("Cookie", mCookies);
                }
                www = new WWW(request.Uri.ToString(), request.Bytes, headers);
            }
            using (www)
            {
                var beginTime = Time.time;
                while (!www.isDone)
                {
                    yield return(null);

                    if (request.Timeout > 0 && Time.time - beginTime >= request.Timeout)
                    {
                        www.Dispose();
                        request.Fail("timeout");
                        yield break;
                    }
                }

                if (www.error == null)
                {
                    BlazeLog.InfoFormat("[HttpClient]text={0}", www.text);
                    request.Finish(www.bytes);
                    performCookies(www);
                }
                else
                {
                    BlazeLog.WarningFormat("[HttpClient]error={0}", www.error);
                    request.Fail(www.error);
                }
            }
        }
예제 #6
0
 protected void OnPreprocessTexture()
 {
     BlazeLog.Info("process " + assetPath);
 }