SimpleSocket 1.0 examples
Dependencies: EthernetNetIf SimpleSocket 1.0 mbed
multicast.cpp
- Committer:
- yamaguch
- Date:
- 2011-10-26
- Revision:
- 32:00114e36de90
- Child:
- 33:39d9cdf99de8
File content as of revision 32:00114e36de90:
#include "EthernetNetIf.h" #include "SimpleSocket.h" void multicast() { printf("DatagramSocket/multicast\n"); Host multicast(IpAddr(239, 192, 1, 100), 50000); DatagramSocket datagram(multicast); while (true) { Host host; if (datagram.receive(&host, 1 + (rand() % 5) / 3.0) > 0) { int value; datagram.scanf("%d", &value); IpAddr ip = host.getIp(); printf("received from %d.%d.%d.%d:%d %d\n", ip[0], ip[1], ip[2], ip[3], host.getPort(), value); } else { char* message = "12345!"; datagram.printf(message); datagram.send(multicast); printf("sent: %s\n", message); wait(1); } } }