Beispiel #1
0
    /// <summary>
    /// Socket消息发送
    /// </summary>
    /// <param name="gameAction">消息id</param>
    /// <param name="boby">内容</param>
    /// <param name="formater">解析协议对象</param>
    /// <param name="bShowLoading">是否显示loading界面</param>
    private void SocketRequest(GameAction gameAction, byte [] boby, IHeadFormater formater, bool bShowLoading)
    {
        if (mSocket == null)
        {
            Debug.LogError("与服务器断开连接,由于服务器无响应");
            Close();
            QueueEvent(EventDef.ServerColsed);
            return;
            //string strUrl = NetWriter.GetUrl();
            //string[] arr = strUrl.Split(new char[] { ':' });
            //int nPort = int.Parse(arr[1]);
            //mSocket = new SocketConnect(arr[0], nPort, formater);
        }
        gameAction.Head.MsgId = NetWriter.MsgId;

        SocketPackage package = new SocketPackage();

        package.MsgId      = (int)gameAction.Head.MsgId;
        package.ActionId   = (int)gameAction.ActionId;
        package.Action     = gameAction;
        package.HasLoading = bShowLoading;
        package.SendTime   = DateTime.Now;
        byte[] data = gameAction.Send(boby);
        NetWriter.resetData();
        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
Beispiel #2
0
    private IEnumerator HttpGetRequest(GameAction gameAction, object userData, IHeadFormater formater, bool showLoading)
    {
        string url = NetWriter.GetUrl();

        byte[]      postData    = gameAction.Send(userData);
        DateTime    start       = DateTime.Now;
        HttpPackage httpPackage = new HttpPackage();

        httpPackage.WwwObject = new WWW(url, postData);
        httpPackage.ActionId  = gameAction.ActionId;
        httpPackage.Action    = gameAction;
        httpPackage.Reader    = new NetReader(formater);
        httpPackage.UserData  = userData;

        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, userData);
    }
Beispiel #3
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.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 #4
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   strUrl = NetWriter.GetUrl();
            string[] arr    = strUrl.Split(new char[] { ':' });
            int      nPort  = int.Parse(arr[1]);
            mSocket = new SocketConnect(arr[0], nPort, formater);
            mSocket.PushCallback += OnPushCallback;
        }
        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 #5
0
 public SocketConnect(string host, int port, IHeadFormater formater)
 {
     this._host = host;
     this._port = port;
     _formater = formater;
     _sendList = new List<SocketPackage>();
     _receiveQueue = new Queue<SocketPackage>();
 }
Beispiel #6
0
 protected CaseStep()
 {
     _stepTimer    = new StepTimer();
     _headFormater = new SOHeadFormater();
     Action        = "";
     _params       = new Dictionary <string, string>();
     Runtimes      = 1;
 }
Beispiel #7
0
 public SocketConnect(string host, int port, IHeadFormater formater)
 {
     this._host    = host;
     this._port    = port;
     _formater     = formater;
     _sendList     = new List <SocketPackage>();
     _receiveQueue = new Queue <SocketPackage>();
 }
Beispiel #8
0
 public SocketConnect(string host, int port, IHeadFormater formater)
 {
     this.Retries       = 0;
     this.mHost         = host;
     this.mPort         = port;
     this.mFormater     = formater;
     this.mSendList     = new List <SocketPackage>();
     this.mReceiveQueue = new Queue <SocketPackage>();
     this.mPushQueue    = new Queue <SocketPackage>();
 }
    public SocketConnect(string host, int port, IHeadFormater formater, int timeOut, int hearInterval)
    {
        this.TimeOut      = timeOut;
        this.HearInterval = hearInterval;

        this._host    = host;
        this._port    = port;
        _formater     = formater;
        _sendList     = new List <SocketPackage>();
        _receiveQueue = new Queue <SocketPackage>();
        _pushQueue    = new Queue <SocketPackage>();
    }
Beispiel #10
0
    static int set_HeadFormater(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Net           obj  = (Net)o;
            IHeadFormater arg0 = (IHeadFormater)ToLua.CheckObject <IHeadFormater>(L, 2);
            obj.HeadFormater = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index HeadFormater on a nil value"));
        }
    }
Beispiel #11
0
    static int get_HeadFormater(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Net           obj = (Net)o;
            IHeadFormater ret = obj.HeadFormater;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index HeadFormater on a nil value"));
        }
    }
Beispiel #12
0
    static int _CreateNetReader(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 1)
        {
            IHeadFormater arg0 = (IHeadFormater)LuaScriptMgr.GetNetObject(L, 1, typeof(IHeadFormater));
            NetReader     obj  = new NetReader(arg0);
            LuaScriptMgr.PushObject(L, obj);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: NetReader.New");
        }

        return(0);
    }
Beispiel #13
0
    //public NetReader()
    //    : this(new DefaultHeadFormater())
    //{
    //}

    public NetReader(IHeadFormater formater)
    {
        _formater = formater;
    }
Beispiel #14
0
 private void HttpRequest(GameAction gameAction, ActionParam actionParam, IHeadFormater formater, bool bShowLoading)
 {
     StartCoroutine(HttpGetRequest(gameAction, actionParam, formater, bShowLoading));
     NetWriter.resetData();
 }
Beispiel #15
0
    private void SocketRequest(int actionId, int actionRespId, LuaFramework.ByteBuffer body, LuaInterface.LuaFunction callback, 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);
        }

        SocketPackage package = new SocketPackage();

        package.MsgId        = NetWriter.MsgId - 1;
        package.ActionId     = actionId;
        package.ActionRespId = actionRespId;
        package.HasLoading   = bShowLoading;
        package.SendTime     = DateTime.Now;
        package.Callback     = callback;

        NetWriter writer = NetWriter.Instance;

        SetActionHead(actionId, body);
        writer.SetBodyData(body.ToBytes());
        byte[] data = writer.PostData();
        NetWriter.resetData();

        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
Beispiel #16
0
    //public NetReader()
    //    : this(new DefaultHeadFormater())
    //{
    //}

    public NetReader(IHeadFormater formater)
    {
        _formater = formater;
    }
Beispiel #17
0
    /// <summary>
    /// parse input data
    /// </summary>
    /// <param name="gameAction"></param>
    /// <param name="userData"></param>
    /// <param name="formater"></param>
    /// <param name="bShowLoading"></param>
    private void SocketRequest(GameAction gameAction, object userData, IHeadFormater formater, bool bShowLoading)
    {
        if (mSocket == null)
        {
            string strUrl = NetWriter.GetUrl();
            string[] arr = strUrl.Split(new char[] { ':' });
            int nPort = int.Parse(arr[1]);
            mSocket = new SocketConnect(arr[0], nPort, formater);
        }
        gameAction.Head.MsgId = NetWriter.MsgId - 1;

        SocketPackage package = new SocketPackage();
        package.UserData = userData;
        package.MsgId = gameAction.Head.MsgId;
        package.ActionId = gameAction.ActionId;
        package.Action = gameAction;
        package.HasLoading = bShowLoading;
        package.SendTime = DateTime.Now;
        byte[] data = gameAction.Send(userData);
        NetWriter.resetData();
        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
Beispiel #18
0
 private void HttpRequest(GameAction gameAction, object userData, IHeadFormater formater, bool bShowLoading)
 {
     StartCoroutine(HttpGetRequest(gameAction, userData, formater, bShowLoading));
     NetWriter.resetData();
 }
Beispiel #19
0
    private IEnumerator HttpGetRequest(GameAction gameAction, object userData, IHeadFormater formater, bool showLoading)
    {
        string url = NetWriter.GetUrl();
        byte[] postData = gameAction.Send(userData);
        DateTime start = DateTime.Now;
        HttpPackage httpPackage = new HttpPackage();
        httpPackage.WwwObject = new WWW(url, postData);
        httpPackage.ActionId = gameAction.ActionId;
        httpPackage.Action = gameAction;
        httpPackage.Reader = new NetReader(formater);
        httpPackage.UserData = userData;

        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, userData);
    }
Beispiel #20
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 #21
0
 private void HttpRequest(GameAction gameAction, ActionParam actionParam, IHeadFormater formater, bool bShowLoading)
 {
     StartCoroutine(HttpGetRequest(gameAction, actionParam, formater, bShowLoading));
     NetWriter.resetData();
 }
Beispiel #22
0
 private void HttpRequest(GameAction gameAction, object userData, IHeadFormater formater, bool bShowLoading)
 {
     StartCoroutine(HttpGetRequest(gameAction, userData, formater, bShowLoading));
     NetWriter.resetData();
 }