Obtaining a UDP socket

USOCKET fnGetUDP_socket(unsigned char ucTOS, int (*fnListener)(USOCKET, unsigned char, unsigned char *, unsigned short, unsigned char *, unsigned short), unsigned char ucOpts));

ucTOS is the type of service defined for IP packets (note that this is presently not used).
fnListener is a user defined call-back handling routine for events belonging to this socket.
ucOpts defines UDP options for this socket and can have the following values:

  • UDP_OPT_CHECK_CS {perform UDP check sum verification on received UDP frames}
  • UDP_OPT_SEND_CS {add a UDP check sum to transmitted UDP frames}
  • 0 {no UDP check sum used}


  • fnGetUDP_socket is called to obtain a UDP socket from the UDP socket pool. The function either returns the socket reference (a non-negative value), or else an error for the following possible reasons:

  • NO_LISTENER_DEFINED {the user has not supplied a mandatory listener function for the socket}
  • NO_FREE_UDP_SOCKETS {there are no free UDP sockets in the UDP socket pool}


  • To reserve extra UDP sockets in the UDP socket pool, the value of USER_UDP_SOCKETS in config.h should be incrimented for each user socket which will be required. Standard UDP services (such as DHCP and DNS) automatically reserve a socket for their own use.

    The obtained socket is not yet bound to a UDP port but is now reserved for such use.

    Project options

    The use of UDP check sum is configured when the socket is obtained and there are no further UDP specific project options.

    Examples

    static USOCKET MyUDP_Socket = -1;
    
    if (!((MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (0))) < 0)) {
        fnBindSocket(MyUDP_Socket, MY_UDP_PORT);            // bind socket
        ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));     // get some memory for UDP frame
    }

    Related functions

    fnReleaseUDP_socket(); fnBindSocket(); fnHandleUDP(); fnSendUDP(); fnReportUDP();


    For more details about the use of UDP in the µTasker project, the following forum thread is recommended about the udp use!



    Please use the µTasker forum to ask specific questions.