Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
registerSocketCallback

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.

Functions

NMI_API void registerSocketCallback (tpfAppSocketCb socket_cb, tpfAppResolveCb resolve_cb)
 

NMI_API void registerSocketCallback ( tpfAppSocketCb  pfAppSocketCb,
tpfAppResolveCb  pfAppResolveCb 
)
Parameters
[in]socket_cbtpfAppSocketCb Assignment 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]resolve_cbtpfAppResolveCb Assignment of callback function to the global callback tpfAppResolveCb gpfAppResolveCb. Used for DNS resolving. 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 the socket functionality 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.

tstrNetworkId strNetworkId;
tstrAuthPsk strAuthPsk;
int8_t ret;
struct sockaddr_in addr;
// Initialize the board
//Initialize the UART console.
// Initialize the BSP.
// Initialize socket address structure.
addr.sin_family = AF_INET;
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.
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
// Connect to router.
strNetworkId.pu8Bssid = NULL;
strNetworkId.pu8Ssid = MAIN_WLAN_SSID;
strNetworkId.u8SsidLen = sizeof(MAIN_WLAN_SSID);
strNetworkId.u8Channel = M2M_WIFI_CH_ALL;
strAuthPsk.pu8Psk = NULL;
strAuthPsk.u8PassphraseLen = (uint8)strlen((char*)MAIN_WLAN_PSK);
m2m_wifi_connect_psk(WIFI_CRED_SAVE_ENCRYPTED, &strNetworkId, &strAuthPsk);

References gpfAppResolveCb, and gpfAppSocketCb.

Referenced by main(), NMI_GrowlInit(), and wifi_ap_provision().