Quantcast
Channel: Wireless Connectivity
Viewing all articles
Browse latest Browse all 116964

Forum Post: RE: Please! How to do an UDP echo server?

$
0
0

I changed the main loop of the basic wifi application for LM4F232 as below:

If the function sendto is removed, each UDP packet received is sent to the Hipertermianal, as expected. When the function sendto is put back, it transmits the first packet back to the network and never returns from the function sendto.

What is wrong?

if( (ulCC3000DHCP == 1) && (ulCC3000Connected == 1) && (printOnce == 1) )
{
printOnce = 0;
DispatcherUartSendPacket((unsigned char*)pucCC3000_Rx_Buffer, strlen((char const*)pucCC3000_Rx_Buffer));

sockaddr tSocketAddr;

UDP_Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

memset(&tSocketAddr, 0, sizeof(tSocketAddr));
tSocketAddr.sa_family = AF_INET;
tSocketAddr.sa_data[0]= (0x0008 & 0xFF00) >> 8;
tSocketAddr.sa_data[1]= (0x0008 & 0x00FF); /* For Testing - Port is a static variable */
tSocketAddr.sa_data[2]= 0x00;
tSocketAddr.sa_data[3]= 0x00;
tSocketAddr.sa_data[4]= 0x00;
tSocketAddr.sa_data[5]= 0x00;
bind(UDP_Socket, &tSocketAddr, sizeof(sockaddr));
binded = 1;
}

if(binded)
{
memset(&timeout, 0, sizeof(timeval));
timeout.tv_sec = 1;
timeout.tv_usec = 0;

// Select only the active connections
FD_ZERO(&readsds);
FD_SET(UDP_Socket, &readsds);
ReturnValue = select(UDP_Socket + 1, &readsds, NULL, NULL, &timeout);
if ((ReturnValue != 0) && (ReturnValue != -1))
{
if (FD_ISSET(UDP_Socket,&readsds))
{
data_received = recvfrom(UDP_Socket, g_ucRxBufB, sizeof(g_ucRxBufB),0, &tSocketAddr, &tRxPacketLength);

if (data_received <= 0)
{
// No data received by device
DispatcherUartSendPacket((unsigned char*)pucUARTNoDataString,sizeof(pucUARTNoDataString));
}
else
{
// Send data to UART...
DispatcherUartSendPacket(g_ucRxBufB, data_received);
// Send data back
ReturnValue = sendto(UDP_Socket, g_ucRxBufB, data_received, 0, &tSocketAddr, sizeof(sockaddr));
ReturnValue = -1;
}


Viewing all articles
Browse latest Browse all 116964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>