Return to SDK Examples for Microchip Studio
#include "ClearCore.h"
#include "EthernetUdp.h"
IpAddress ip = IpAddress(192, 168, 1, 177);
uint16_t localPort = 8888;
#define MAX_PACKET_LENGTH 100
unsigned char packetReceived[MAX_PACKET_LENGTH];
EthernetUdp Udp;
bool usingDhcp = true;
int main() {
uint32_t timeout = 5000;
while (!ConnectorUsb &&
Milliseconds() - startTime < timeout) {
continue;
}
}
if (usingDhcp) {
if (dhcpSuccess) {
}
else {
while (true) {
continue;
}
}
}
else {
}
Udp.Begin(localPort);
while (true) {
uint16_t packetSize = Udp.PacketParse();
if (packetSize > 0) {
int32_t bytesRead = Udp.PacketRead(packetReceived, MAX_PACKET_LENGTH);
Udp.Connect(Udp.RemoteIp(), Udp.RemotePort());
Udp.PacketWrite("Hello, world!");
Udp.PacketSend();
}
}
}