Пример #1
0
        public void OnRecv(object target, SocketAsyncEventArgs e)
        {
            IOSocket io = new IOSocket(e.Buffer); // 思考下这里怎么避免重复new对象 避免gc

            io.Seek(0);
            int type = io.ReadInt32();

            switch (type)
            {
            case NetMsgDefine.HeadBeat:
            {
                lastrecvTime = Environment.TickCount;
                Console.WriteLine("收到客户端心跳包" + io.ReadByte().ToString());
                Recv();
            }

            break;

            default:
                break;
            }
        }
Пример #2
0
        public void OnRecv(object sender, SocketAsyncEventArgs e)
        {
            IOSocket io = new IOSocket(e.Buffer);

            io.Seek(0);

            int type = io.ReadInt32();

            switch (type)
            {
            case NetMsgDefine.sayhello:
            {
                string str = io.ReadString16();
                Console.WriteLine(str);
            }

            break;

            case NetMsgDefine.HeadBeat:
            {
                Console.WriteLine("心跳到这里来了吗?");
                string str = io.ReadByte().ToString();
                Console.WriteLine(str);
            }

            break;

            case NetMsgDefine.GameLogic:
                break;

            default:
                break;
            }



            this.Recv(); // 成功recv之后继续recv 我们测试客户
        }