Ejemplo n.º 1
0
        /// <summary>
        /// 是否重新连接
        /// </summary>
        /// <param name="_serverType">服务器ID</param>
        /// <param name="_isFirstConnect">是否第一次连接</param>
        public bool IsReConnect(int _serverType, bool _isFirstConnect = true)
        {
            // 这里控制能重新登录指定的次数
            if (reconnectNum > MAX_RECONNECT_COUNT)
            {
                // 重新登录的次数达到目标次数,返回连接失败
                ReConnectFail(_serverType);
                return(false);
            }

            SocketClientProxy tempSocket = GetSocket(_serverType);

            if (tempSocket == null)
            {
                return(false);
            }

            reconnectNum++;
            if (_isFirstConnect)
            {
                reconnectTime = Time.time;
                tempSocket.ReConnect();
                return(true);
            }

            // 重置连接的数据
            tempSocket.ReConnect();
            return(true);
        }
    static int _CreateGameFramework_SocketClientProxy(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                GameFramework.SocketClientProxy obj = new GameFramework.SocketClientProxy();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1)
            {
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 1);
                GameFramework.SocketClientProxy obj = new GameFramework.SocketClientProxy(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: GameFramework.SocketClientProxy.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// 发送成功就回调的发送方式,不需要返回数据,支持断网缓存用户操作
        /// </summary>
        /// <param name="_data">发送数据</param>
        /// <param name="_serviceid">协议ID</param>
        /// <param name="_requestData">上传的数据,会原样返回</param>
        public void SendData(int _serverType, byte[] _data, uint _serviceid, object _requestData)
        {
            SocketClientProxy tempSocket = GetSocket(_serverType);

            if (tempSocket == null)
            {
                return;
            }

            tempSocket.SendData(_data, _serviceid, _requestData);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 关闭和清除连接
        /// </summary>
        /// <param name="_serverType">服务器类型</param>
        public void OnCloseAndClearTcp(int _serverType)
        {
            SocketClientProxy tempSocket = GetSocket(_serverType);

            if (tempSocket == null)
            {
                return;
            }

            tempSocket.CloseAndInitTcp();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 删除网络服务监听
        /// </summary>
        /// <param name="service">服务接口类型</param>
        /// <param name="_callBack">回调函数</param>
        public void RemoveListener(int _serverType, uint _serviceId, LuaFunction _callBack)
        {
            SocketClientProxy tempSocket = GetSocket(_serverType);

            if (tempSocket == null)
            {
                return;
            }

            tempSocket.RemoveListener(_serviceId, _callBack);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 判断服务器是否连接
        /// </summary>
        /// <param name="_serverType">服务器类型,服务器是可以有很多个的</param>
        public bool IsConnected(int _serverType, bool _really = false)
        {
            SocketClientProxy tempSocket = GetSocket(_serverType);

            if (tempSocket == null)
            {
                return(false);
            }

            return(tempSocket.IsConnected(_really));
        }
 static int Clear(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         GameFramework.SocketClientProxy obj = (GameFramework.SocketClientProxy)ToLua.CheckObject <GameFramework.SocketClientProxy>(L, 1);
         obj.Clear();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int RemoveListener(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         GameFramework.SocketClientProxy obj = (GameFramework.SocketClientProxy)ToLua.CheckObject <GameFramework.SocketClientProxy>(L, 1);
         uint        arg0 = (uint)LuaDLL.luaL_checknumber(L, 2);
         LuaFunction arg1 = ToLua.CheckLuaFunction(L, 3);
         obj.RemoveListener(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 取socket实例
        /// </summary>
        SocketClientProxy GetSocket(int _serverType = 1)
        {
            if (socketList == null)
            {
                return(null);
            }

            SocketClientProxy tempSocket = socketList.Find(delegate(SocketClientProxy _socket) { return(_socket.ServerType == _serverType); });

            if (tempSocket == null)
            {
                tempSocket = new SocketClientProxy(_serverType);
                socketList.Add(tempSocket);
            }

            return(tempSocket);
        }
 static int SendData(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         GameFramework.SocketClientProxy obj = (GameFramework.SocketClientProxy)ToLua.CheckObject <GameFramework.SocketClientProxy>(L, 1);
         byte[] arg0 = ToLua.CheckByteBuffer(L, 2);
         uint   arg1 = (uint)LuaDLL.luaL_checknumber(L, 3);
         object arg2 = ToLua.ToVarObject(L, 4);
         obj.SendData(arg0, arg1, arg2);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    static int set_onNetDataError(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            GameFramework.SocketClientProxy           obj  = (GameFramework.SocketClientProxy)o;
            System.Action <GameFramework.SessionData> arg0 = (System.Action <GameFramework.SessionData>)ToLua.CheckDelegate <System.Action <GameFramework.SessionData> >(L, 2);
            obj.onNetDataError = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index onNetDataError on a nil value"));
        }
    }
    static int get_onNetDataError(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            GameFramework.SocketClientProxy           obj = (GameFramework.SocketClientProxy)o;
            System.Action <GameFramework.SessionData> ret = obj.onNetDataError;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index onNetDataError on a nil value"));
        }
    }
Ejemplo n.º 13
0
        /// <summary>
        /// 连接服务器
        /// </summary>
        /// <param name="_serverType">服务器类型</param>
        /// <param name="_host">主机</param>
        /// <param name="_port">端口</param>
        public void ConnectAsync(int _serverType, string _host, int _port, LuaFunction _onConnected, LuaFunction _onDisconnected, LuaFunction _onConnectFailed, LuaFunction _onReConnectFailed)
        {
            if (socketList == null)
            {
                return;
            }
            SocketClientProxy tempSocket = GetSocket(_serverType);

            if (tempSocket == null)
            {
                return;
            }
            isConnected       = false;
            onConnected       = _onConnected;
            onDisconnected    = _onDisconnected;
            onConnectFailed   = _onConnectFailed;
            onReConnectFailed = _onReConnectFailed;

            // 同步连接
            tempSocket.Connect(_host, _port);
        }