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;
// Initialize the board
system_init();
//Initialize the UART console.
// Initialize the BSP.
// Initialize socket address structure.
// 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);
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.
Parameters
[in]socket_cbAssignment 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_cbAssignment of callback function to the global callback tpfAppResolveCb gpfAppResolveCb. Used for DNS resolving functionality. 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 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;
// Initialize the board
system_init();
//Initialize the UART console.
// Initialize the BSP.
// Initialize socket address structure.
// 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);