#include "net\udp.h" //Create a UDP socket for receiving and sending data static UDP_SOCKET udpSocketUser = INVALID_UDP_SOCKET; void udpExample(void) { BYTE c; NODE_INFO udpServerNode; //Initialize remote IP and MAC address of udpServerNode with 0, seeing that we //don't know them for the node that will send us an UDP message. The first time //a message is received addressed to this port, the remote IP and MAC addresses //are automatically updated with the addresses of the remote node. memclr(&udpServerNode, sizeof(udpServerNode)); //Configure for local port 54123 and remote port INVALID_UDP_PORT. This opens //the socket to listen on the given port. udpSocketUser = UDPOpen(54123, &udpServerNode, INVALID_UDP_PORT); //An error occurred during the UDPOpen() function if (udpSocketUser == INVALID_UDP_SOCKET) { //Add user code here to take action if required! } //Infinite loop. Check if anything is received on UDP port while(1) { //Is there any data waiting for us on the UDP socket? //Because of the design of the Modtronix TCP/IP stack we have to consume //all data sent to us as soon as we detect it. if (UDPIsGetReady(udpSocketUser)) { //We are only interrested in the first byte of the message. UDPGet(&c); if (c == '0') LATB6 = 0; //Switch system LED off else if (c == '1') LATB6 = 1; //Switch system LED on //Discard the socket buffer. UDPDiscard(); } //This task performs normal stack task including checking for incoming //packet, type of packet and calling appropriate stack entity to //process it. StackTask(); } }