Hi,
There was actually a bug in the UDP sockets implementation. This was oddly working fine with the NTP Client, but since the program here is acting as a server(although the client/server distinction doesn't make much sense with UDP) this bug is revealing itself...
With the new version I published today your program should be working fine, however there's a small bug in your program as well since you use the client's address before setting it at some point; it should look like:
void EchoServer::onNetUdpSocketEvent(UDPSocketEvent e) {
// We're only interested in the READABLE event (it's the only one)
if ( e == UDPSOCKET_READABLE ) {
// No need for a handler for UDP - set up a buffer and check client
char buff[128];
Host client;
// Keep reading while there's data to be read
while ( int len = udpSock->recvfrom(buff, 128, &client) ) {
if ( len > 0 )
// If there's data, send it straight back out
udpSock->sendto(buff, len, &client);
}
IpAddr clientIp = client.getIp();
printf("Incoming UDP connection from %d.%d.%d.%d\r\n", clientIp[0], clientIp[1], clientIp[2], clientIp[3]);
}
}
For my tests, I've been using Python in command-line mode, the sockets API from the standard library is pretty straightforward.
Cheers,
Donatien
Hi all,
I've just spent the afternoon playing around with Donatien's new network framework, specifically playing directly with the socket API. I've got the TCP side up and running okay doing what I expected it to, but for some reason I don't seem to be able to get anything happening on UDP.
The relevant bits of the code are:
The full program is available at http://mbed.org/users/darran/programs/EchoServer
Is there something obvious I'm doing wrong? Admittedly it could be down to me not even sending UDP packets to the mbed correctly. I've tried both PCATTCP (http://www.pcausa.com/Utilities/pcattcp.htm) and a small Java program I found and modified to point to my mbed's IP address (http://www.java2s.com/Tutorial/Java/0320__Network/UDPEchoClient.htm). Neither of which appear to be eliciting any UDP events at all.
Any pointers gratefully appreciated.