SimpleSocket 1.0 examples

Dependencies:   EthernetNetIf SimpleSocket 1.0 mbed

Committer:
yamaguch
Date:
Mon Feb 04 09:04:25 2013 +0000
Revision:
40:84182fc63956
Parent:
udpreceiver.cpp@39:108499af2b53
changed SimpleSocket libary name to SimpleSocketV1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yamaguch 39:108499af2b53 1 #include "EthernetNetIf.h"
yamaguch 39:108499af2b53 2 #include "SimpleSocket.h"
yamaguch 39:108499af2b53 3
yamaguch 39:108499af2b53 4 void udpreceiver() {
yamaguch 39:108499af2b53 5 EthernetNetIf eth;
yamaguch 39:108499af2b53 6 eth.setup();
yamaguch 39:108499af2b53 7
yamaguch 39:108499af2b53 8 DatagramSocket datagram(7777);
yamaguch 39:108499af2b53 9
yamaguch 39:108499af2b53 10 Host buddy;
yamaguch 39:108499af2b53 11 while (true) {
yamaguch 39:108499af2b53 12 if (datagram.receive(&buddy, 1) > 0) {
yamaguch 39:108499af2b53 13 IpAddr ip = buddy.getIp();
yamaguch 39:108499af2b53 14 int port = buddy.getPort();
yamaguch 39:108499af2b53 15 char buf[80] = {};
yamaguch 39:108499af2b53 16 int len = datagram.read(buf, sizeof(buf) - 1);
yamaguch 39:108499af2b53 17 printf("received from %d.%d.%d.%d:%d %s", ip[0],ip[1], ip[2], ip[3], port, buf);
yamaguch 39:108499af2b53 18 }
yamaguch 39:108499af2b53 19 }
yamaguch 39:108499af2b53 20 }