Beispiel #1
0
        /// <summary>
        /// parse input data
        /// </summary>
        /// <param name="gameAction"></param>
        /// <param name="actionParam"></param>
        /// <param name="formater"></param>
        /// <param name="bShowLoading"></param>
        private void SocketRequest(GameAction gameAction, ActionParam actionParam, IHeadFormater formater, bool bShowLoading)
        {
            if (mSocket == null)
            {
                string url = NetWriter.GetUrl();
                string[] arr = url.Split(new char[] { ':' });
                if (arr.Length != 2)
                {
                    Debug.LogError("Url is error:" + url);
                    return;
                }
                int nPort = int.Parse(arr[1]);
                mSocket = new SocketConnect(arr[0], nPort, formater);

            }
            gameAction.Head.MsgId = NetWriter.MsgId - 1;

            SocketPackage package = new SocketPackage();
            package.MsgId = gameAction.Head.MsgId;
            package.ActionId = gameAction.ActionId;
            package.Action = gameAction;
            package.HasLoading = bShowLoading;
            package.SendTime = DateTime.Now;
            byte[] data = gameAction.Send(actionParam);
            NetWriter.resetData();
            if (bShowLoading)
            {
                RequestDelegate(Status.eStartRequest);
            }
            mSocket.Send(data, package);
        }
Beispiel #2
0
        private IEnumerator HttpGetRequest(GameAction gameAction, ActionParam actionParam, IHeadFormater formater, bool showLoading)
        {
            string url = NetWriter.GetUrl();
            byte[] postData = gameAction.Send(actionParam);
            DateTime start = DateTime.Now;
            HttpPackage httpPackage = new HttpPackage();
            httpPackage.WwwObject = NetWriter.IsGet ? new WWW(string.Format("{0}?{1}", url, Encoding.UTF8.GetString(postData))) : new WWW(url, postData);
            httpPackage.ActionId = gameAction.ActionId;
            httpPackage.Action = gameAction;
            httpPackage.Reader = new NetReader(formater);

            if (RequestNotify != null && showLoading)
            {
                RequestNotify(Net.Status.eStartRequest);
            }

            yield return httpPackage.WwwObject;

            if (RequestNotify != null && showLoading)
            {
                RequestNotify(Net.Status.eEndRequest);
            }
            TimeSpan tsStart = new TimeSpan(start.Ticks);
            TimeSpan tsEnd = new TimeSpan(DateTime.Now.Ticks);
            TimeSpan ts = tsEnd.Subtract(tsStart).Duration();

            if (ts.Seconds > OVER_TIME)
            {
                httpPackage.IsOverTime = true;
            }
            OnHttpRespond(httpPackage);
        }