public int SendUnreliable <T>(IPacket <T> packet) { int sendSize = 0; if (m_udp != null) { // 모듈에서 사용할 헤더 정보를 생성합니다. PacketHeader header = new PacketHeader(); HeaderSerializer serializer = new HeaderSerializer(); header.packetId = packet.GetPacketId(); byte[] headerData = null; if (serializer.Serialize(header) == true) { headerData = serializer.GetSerializedData(); } byte[] packetData = packet.GetData(); byte[] data = new byte[headerData.Length + packetData.Length]; int headerSize = Marshal.SizeOf(typeof(PacketHeader)); Buffer.BlockCopy(headerData, 0, data, 0, headerSize); Buffer.BlockCopy(packetData, 0, data, headerSize, packetData.Length); sendSize = m_udp.Send(data, data.Length); } return(sendSize); }
//********************************************************************* /// <summary> /// Demo to send packets in three different ways /// </summary> /// <param name="message"></param> /// <returns></returns> //********************************************************************* public static bool Demo() { byte[] bites = { 0, 1, 2, 3, 4 }; string sturing = ""; var sampleClass = new SampleClass(); var transport = new TransportUdp("192.168.1.255", 45678); // Byte array transport.Send(bites); // String transport.Send(sturing); // Class (get serialized before transmission) transport.Send(sampleClass); return(true); }