Hi @akift,
I'm not sure @kerryzhou understood your question.
I have managed to receive broadcasts using code like the following snippet:
struct netconn *pListenerConnection = netconn_new(NETCONN_UDP);
if (!pListenerConnection)
{
// failed to listen
DebugPrintf("listener failed on netconn_new()\n");
goto restart;
}
struct netbuf *pBuf;
lastNetError = netconn_bind(pListenerConnection, IP_ADDR_ANY, listenPort);
if (ERR_OK != lastNetError)
{
// failed to listen
DebugPrintf("Listener failed on netconn_bind(), return %i\n", lastNetError);
netconn_delete(pListenerConnection);
goto restart;
}
// process requests from possible clients.
while (1)
{
lastNetError = netconn_recv(pListenerConnection, &pBuf);
// depending on the return
if (ERR_OK != lastNetError)
{
// some error.
DebugPrintf("listener got error %i in netconn_recv()\n", lastNetError);
// restart the connection
netconn_delete(pListenerConnection);
goto restart;
};
// pBuf has the message:
uint8_t packet[8]; // just interested in the first this many bytes
size_t packetSize = netbuf_copy(pBuf, packet, sizeof(packet));
if (packetSize != sizeof(packet))
{
DebugPrintf("listener got an unexpected request, not %d bytes long.\n", packetSize);
// delete the pBuf and wait for another UDP packet.
netbuf_delete(pBuf);
continue;
}
// use the data in packet.
netbuf_delete(pBuf);
}
I hope it helps.
Cheers,