static int IsConnected(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                GameFramework.SocketTcp obj = (GameFramework.SocketTcp)ToLua.CheckObject <GameFramework.SocketTcp>(L, 1);
                bool o = obj.IsConnected();
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 2)
            {
                GameFramework.SocketTcp obj = (GameFramework.SocketTcp)ToLua.CheckObject <GameFramework.SocketTcp>(L, 1);
                bool arg0 = LuaDLL.luaL_checkboolean(L, 2);
                bool o    = obj.IsConnected(arg0);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: GameFramework.SocketTcp.IsConnected"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    static int Connect(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                GameFramework.SocketTcp obj = (GameFramework.SocketTcp)ToLua.CheckObject <GameFramework.SocketTcp>(L, 1);
                obj.Connect();
                return(0);
            }
            else if (count == 3)
            {
                GameFramework.SocketTcp obj = (GameFramework.SocketTcp)ToLua.CheckObject <GameFramework.SocketTcp>(L, 1);
                string arg0 = ToLua.CheckString(L, 2);
                int    arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                obj.Connect(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: GameFramework.SocketTcp.Connect"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
 static int Clear(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         GameFramework.SocketTcp obj = (GameFramework.SocketTcp)ToLua.CheckObject <GameFramework.SocketTcp>(L, 1);
         obj.Clear();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int Send(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         GameFramework.SocketTcp obj = (GameFramework.SocketTcp)ToLua.CheckObject <GameFramework.SocketTcp>(L, 1);
         byte[] arg0 = ToLua.CheckByteBuffer(L, 2);
         obj.Send(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int SetAddress(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         GameFramework.SocketTcp obj = (GameFramework.SocketTcp)ToLua.CheckObject <GameFramework.SocketTcp>(L, 1);
         string arg0 = ToLua.CheckString(L, 2);
         int    arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
         obj.SetAddress(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    static int get_IsStartConnect(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            GameFramework.SocketTcp obj = (GameFramework.SocketTcp)o;
            bool ret = obj.IsStartConnect;
            LuaDLL.lua_pushboolean(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index IsStartConnect on a nil value"));
        }
    }
    static int get_ErrorMessage(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            GameFramework.SocketTcp obj = (GameFramework.SocketTcp)o;
            string ret = obj.ErrorMessage;
            LuaDLL.lua_pushstring(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index ErrorMessage on a nil value"));
        }
    }
    static int get_ServerType(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            GameFramework.SocketTcp obj = (GameFramework.SocketTcp)o;
            int ret = obj.ServerType;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index ServerType on a nil value"));
        }
    }
Esempio n. 9
0
        /// <summary>
        /// 连接服务器失败会响应这个事件
        /// </summary>
        /// <param name="_socketTcp">断开连接的Socket</param>
        void OnConnectFailed(object _socket)
        {
            SocketTcp tempSocketTcp = _socket as SocketTcp;

            if (tempSocketTcp == null)
            {
                return;
            }

            if (reConnectList != null && !reConnectList.Contains(tempSocketTcp.ServerType))
            {
                reConnectList.Add(tempSocketTcp.ServerType);
            }

            if (onConnectFailed != null)
            {
                onConnectFailed.Call(tempSocketTcp);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 从服务器断开连接会响应这个事件
        /// </summary>
        /// <param name="_socker">断开连接的Socket</param>
        void OnDisconnected(object _socker)
        {
            SocketTcp tempSocketTcp = _socker as SocketTcp;

            if (tempSocketTcp == null)
            {
                return;
            }

            // 非连接状态才会启动断线重连,目前只有在登录的时候才会启动断线重连
            if (!isConnected && reConnectList != null && !reConnectList.Contains(tempSocketTcp.ServerType))
            {
                reConnectList.Add(tempSocketTcp.ServerType);
            }

            if (onDisconnected != null)
            {
                // 通知 Lua 网络断开
                onDisconnected.Call(tempSocketTcp);
            }
        }
    static int _CreateGameFramework_SocketTcp(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 1);
                GameFramework.SocketTcp obj = new GameFramework.SocketTcp(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: GameFramework.SocketTcp.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 12
0
        /// <summary>
        /// 成功连接会触发这个事件
        /// </summary>
        /// <param name="_socker">连接成功的Socket</param>
        void OnConnected(object _socker)
        {
            SocketTcp tempSocketTcp = _socker as SocketTcp;

            if (tempSocketTcp == null)
            {
                return;
            }

            if (reConnectList != null && reConnectList.Contains(tempSocketTcp.ServerType))
            {
                reConnectList.Remove(tempSocketTcp.ServerType);
            }

            // 发送成功连接事件
            if (onConnected != null)
            {
                onConnected.Call(tempSocketTcp);
            }

            // 登录成功之后,复位断线重连次数
            reconnectNum = 0;
            isConnected  = true;
        }