UDP_SOCKET UDPOpenEx( DWORD remoteHost, BYTE remoteHostType, UDP_PORT localPort, UDP_PORT remotePort );
Provides a unified method for opening UDP sockets. This function can open both client and server sockets. For client sockets, it can accept a host name string to query in DNS, an IP address as a string, an IP address in binary form, or a previously resolved NODE_INFO structure containing the remote IP address and associated MAC address. When a host name or IP address only is provided, UDP module will internally perform the necessary DNSResolve and/or ARP resolution steps before reporting that the UDP socket is connected (via a call to UDPISOpen returning TRUE). Server sockets ignore this destination parameter and listen only on the indicated port. Sockets are statically allocated on boot, but can be claimed with this function and freed using UDPClose .
UDPInit should be called.
Parameters |
Description |
remoteHost |
Pointer to remote node info (MAC and IP address) for this connection. If this is a server socket (receives the first packet) or the destination is the broadcast address, then this parameter should be NULL. For client sockets only. Provide a pointer to a null-terminated string of the remote host name (ex:"www.microchip.com" or "192.168.1.123"), a literal destination IP address (ex: 0x7B01A8C0 or an IP_ADDR data type), or a pointer to a NODE_INFO structure with the remote IP address and remote node or gateway MAC address specified, If a string is provided. |
remoteHostType |
Any one of the following flags to identify the meaning of the remoteHost parameter:
|
localPort |
UDP port number to listen on. If 0, stack will dynamically assign a unique port number to use. |
remotePort |
For client sockets, the remote port number. |
Return Values |
Description |
Success |
A UDP socket handle that can be used for subsequent UDP API calls. |
Failure |
INVALID_UDP_SOCKET. This function fails when no more UDP socket handles are available. Increase MAX_UDP_SOCKETS to make more sockets available. |
When finished using the UDP socket handle, call the UDPClose() function to free the socket and delete the handle.