private static void IPv4_UDPHandler(byte[] packetData) { UDP.UDPPacket udp_packet = new UDP.UDPPacket(packetData); if (udpClients.ContainsKey(udp_packet.DestinationPort) == true) { DataReceived dlgt = udpClients[udp_packet.DestinationPort]; if (dlgt != null) { dlgt(new IPv4EndPoint(udp_packet.SourceIP, udp_packet.SourcePort), udp_packet.UDP_Data); } } }
/// <summary> /// Send a UDP packet to a destination device /// </summary> /// <param name="dest">IP address of destination</param> /// <param name="srcPort">Source port</param> /// <param name="destPort">Destination port to send data to</param> /// <param name="data">Data to be sent</param> public static void SendUDP(IPv4Address dest, UInt16 srcPort, UInt16 destPort, byte[] data) { IPv4Address source = FindNetwork(dest); if (source == null) { Console.WriteLine("Destination Network Unreachable!!"); return; } UDP.UDPPacket outgoing = new UDP.UDPPacket(source, dest, srcPort, destPort, data); TCPIP.IPv4OutgoingBuffer.AddPacket(outgoing); }