SimpleSocket 1.0 examples

Dependencies:   EthernetNetIf SimpleSocket 1.0 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers udpreceiver.cpp Source File

udpreceiver.cpp

00001 #include "EthernetNetIf.h"
00002 #include "SimpleSocket.h"
00003 
00004 void udpreceiver() {
00005     EthernetNetIf eth;
00006     eth.setup();
00007     
00008     DatagramSocket datagram(7777);
00009 
00010     Host buddy;
00011     while (true) {
00012         if (datagram.receive(&buddy, 1) > 0) {
00013             IpAddr ip = buddy.getIp();
00014             int port = buddy.getPort();
00015             char buf[80] = {};
00016             int len = datagram.read(buf, sizeof(buf) - 1);
00017             printf("received from %d.%d.%d.%d:%d %s", ip[0],ip[1], ip[2], ip[3], port, buf);
00018         }
00019     }
00020 }