public override void OnConnected(EndPoint endPoint)
        {
            Console.WriteLine($"OnConnected : {endPoint}");
            PlayerInfoReq packet = new PlayerInfoReq()
            {
                playerId = 1001, name = "HELLO"
            };

            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 101, level = 1, duration = 3.0f
            });
            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 201, level = 2, duration = 4.0f
            });
            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 301, level = 3, duration = 5.0f
            });
            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 401, level = 4, duration = 6.0f
            });

            //for (int i = 0; i < 5; i++)
            {
                ArraySegment <byte> s = packet.Write();
                #region 주석처리
                //byte[] size = BitConverter.GetBytes(packet.size);
                //byte[] packetId = BitConverter.GetBytes(packet.packetId);
                //byte[] playerId = BitConverter.GetBytes(packet.playerId);

                //Array.Copy(size, 0, s.Array, s.Offset+count, 2);
                //count += 2;
                //Array.Copy(packetId, 0, s.Array, s.Offset + count, 2);
                //count += 2;
                //Array.Copy(playerId, 0, s.Array, s.Offset+count, 8);
                //count += 8;
                #endregion

                //궁금점? : 왜 큰 버퍼를 두고 잘라 사용해야하는가? 길이를 안다면 그만큼만 보내면 되는 것 아닌가?
                // -> 가변적 + 메모리 낭비 줄이기
                if (s != null)
                {
                    Send(s);
                }
            }
        }
Example #2
0
        // 참고 (c#에서 포인터 사용)

        /*
         * static unsafe void ToBytes(byte[] array, int offset, ulong value)
         * {
         *  fixed (byte* ptr = &array[offset])
         *(ulong*)ptr = value;
         * }
         */


        public override void OnConnected(EndPoint endPoint)
        {
            Console.WriteLine($"OnConnected: {endPoint}");

            PlayerInfoReq packet = new PlayerInfoReq()
            {
                playerId = 1001, name = "ABCD"
            };

            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 101, level = 1, duration = 3.0f
            });
            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 201, level = 2, duration = 1.0f
            });
            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 301, level = 3, duration = 2.0f
            });
            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 401, level = 4, duration = 4.0f
            });

            // Send
            // for (int i = 0; i < 10; i++)
            {
                ArraySegment <byte> s = packet.Write();

                if (s != null)
                {
                    Send(s);
                }
            }
        }
Example #3
0
        public override void OnConnected(EndPoint endPoint)
        {
            Console.WriteLine($"Connected: {endPoint}");

            PlayerInfoReq packet = new PlayerInfoReq()
            {
                playerID = 1001, name = "SeungHu"
            };

            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 101, level = 1, duration = 3.75f
            });
            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 201, level = 2, duration = 2.75f
            });
            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 301, level = 3, duration = 1.75f
            });
            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 401, level = 4, duration = 1.5f
            });
            packet.skills.Add(new PlayerInfoReq.SkillInfo()
            {
                id = 501, level = 5, duration = 0.75f
            });

            ArraySegment <byte> sendBuff = packet.Write();

            if (sendBuff != null)
            {
                Send(sendBuff);
            }
        }