Delta / NNN50_WIFI_API

Dependents:   NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more

Embed: (wiki syntax)

« Back to documentation index

registerSocketCallback

registerSocketCallback
[Function]

Register two callback functions one for asynchronous socket events and the other one for DNS callback registering function. More...

Functions

NMI_API void registerSocketCallback (tpfAppSocketCb socket_cb, tpfAppResolveCb resolve_cb)

Detailed Description

Register two callback functions one for asynchronous socket events and the other one for DNS callback registering function.

The registered callback functions are used to retrieve information in response to the asynchronous socket functions called.


Function Documentation

NMI_API void registerSocketCallback ( tpfAppSocketCb  socket_cb,
tpfAppResolveCb  resolve_cb 
)
Parameters:
[in]tpfAppSocketCbAssignment of callback function to the global callback tpfAppSocketCb gpfAppSocketCb. Delivers socket messages to the host application. In response to the asynchronous function calls, such as bind listen accept connect
[in]tpfAppResolveCbAssignment of callback function to the global callback tpfAppResolveCb gpfAppResolveCb. Used for DNS resolving functionalities. The DNS resolving technique is determined by the application registering the callback. NULL is assigned when, DNS resolution is not required.
Returns:
void
Remarks:
If any of the socket functionalities is not to be used, NULL is passed in as a parameter. It must be invoked after socketinit and before other socket layer operations.

Example

This example demonstrates the use of the registerSocketCallback to register a socket callback function with DNS resolution CB set to null for a simple UDP server example.

        tstrWifiInitParam param;
    int8_t ret;
    struct sockaddr_in addr;

    // Initialize the board
    system_init();

    //Initialize the UART console. 
    configure_console();
    
    // Initialize the BSP.
    nm_bsp_init();

    // Initialize socket address structure.
    addr.sin_family = AF_INET;
    addr.sin_port = _htons(MAIN_WIFI_M2M_SERVER_PORT);
    addr.sin_addr.s_addr = _htonl(MAIN_WIFI_M2M_SERVER_IP);

    // Initialize Wi-Fi parameters structure. 
    memset((uint8_t *)&param, 0, sizeof(tstrWifiInitParam));

    // Initialize Wi-Fi driver with data and status callbacks.
    param.pfAppWifiCb = wifi_cb;
    ret = m2m_wifi_init(&param);
    if (M2M_SUCCESS != ret) {
        printf("main: m2m_wifi_init call error!(%d)\r\n", ret);
        while (1) {
        }
    }

    // Initialize socket module
    socketInit ();
    registerSocketCallback (socket_cb, NULL);

    // Connect to router.
    m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL);