コード例 #1
0
ファイル: Program.cs プロジェクト: ly774508966/GTLib
        public void ConnectTest(string ip, int port)
        {
            MPNetClient mpnet = new MPNetClient(m_PrefabConnecterId);

            mpnet.Connect(ip, port);

            mpnet.AddEventListener(MPEvent.CONNECTION, delegate(BaseEvent evt)
            {
                Hashtable par = evt.Params;
                if ((bool)par["success"])
                {
                    DispatchEvent(new MPEvent(Program.EVENT_CONNECT + m_PrefabConnecterId));
                }
                else
                {
                    DispatchEvent(new MPEvent(Program.EVENT_CONNECT_LOST + m_PrefabConnecterId));
                }
            });
            mpnet.AddEventListener(MPEvent.CONNECTION_LOST, delegate(BaseEvent evt)
            {
                GTLib.NetManager.KillConnection(m_PrefabConnecterId);
                DispatchEvent(new MPEvent(Program.EVENT_CONNECT_LOST + m_PrefabConnecterId));
            });

            GTLib.NetManager.AddMPNetClient(mpnet);
        }
コード例 #2
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="ip"></param>
    /// <param name="port"></param>
    public void Connect(string ip, int port)
    {
        MPNetClient mpnet = new MPNetClient(m_PrefabConnecterId);

        mpnet.Connect(ip, port);

        mpnet.AddEventListener(MPEvent.CONNECTION, delegate(BaseEvent evt)
        {
            IMPObject par = evt.Params;
            if ((bool)par["success"])
            {
                IMPObject mpo  = MPObject.NewInstance();
                mpo["test1"]   = 22;
                mpo["test2"]   = 22;
                mpo["test3"]   = 33;
                LuaTable table = mpo.ToLuaTable();
                GTLib.NetManager.DispatchLuaEvent("conn1", table);
            }
            else
            {
                GTLib.NetManager.DispatchLuaEvent("lost1", null);
            }
        });
        mpnet.AddEventListener(MPEvent.CONNECTION_LOST, delegate(BaseEvent evt)
        {
            GTLib.NetManager.KillConnection(m_PrefabConnecterId);
            GTLib.NetManager.DispatchLuaEvent("lost1", null);
        });

        GTLib.NetManager.AddMPNetClient(mpnet);
    }