public override void OnConnected(EndPoint endPoint) { Console.WriteLine($"{endPoint}에 연결되었습니다."); PlayerInfoReq packet = new PlayerInfoReq() { playerId = 1001 }; for (int i = 0; i < 5; i++) { // 이제 패킷 타입만 PlayerInfoReq로 선언하면, // Serialize()를 통해 해당 클래스 구성을 몰라도 직렬화할 수 있다. ArraySegment <byte> sendBuff = packet.Serialize(); if (sendBuff != null) { Send(sendBuff); } } }
public override void OnConnected(EndPoint endPoint) { Console.WriteLine($"{endPoint}에 연결되었습니다."); PlayerInfoReq packet = new PlayerInfoReq() { playerId = 1001, playerName = "태사단" }; packet.skills.Add(new PlayerInfoReq.SkillInfo() { id = 101, level = 5, duration = 0.3f }); packet.skills.Add(new PlayerInfoReq.SkillInfo() { id = 102, level = 7, duration = 20f }); packet.skills.Add(new PlayerInfoReq.SkillInfo() { id = 105, level = 1, duration = 3f }); packet.skills.Add(new PlayerInfoReq.SkillInfo() { id = 201, level = 2, duration = 0.05f }); for (int i = 0; i < 5; i++) { // 이제 패킷 타입만 PlayerInfoReq로 선언하면, // Serialize()를 통해 해당 클래스 구성을 몰라도 직렬화할 수 있다. ArraySegment <byte> sendBuff = packet.Serialize(); if (sendBuff != null) { Send(sendBuff); } } }