Simple code for comunication via TCP between the mbed and PC.
Dependencies: EthernetInterface SimpleSocket mbed-rtos mbed
Fork of SimpleSocketExamples by
examples/udpsender.cpp
- Committer:
- numeral369
- Date:
- 2014-12-17
- Revision:
- 1:016774025718
- Parent:
- 0:6dc3cfd058c6
File content as of revision 1:016774025718:
#include "SimpleSocket.h" void udpsender() { DatagramSocket datagram; char message[80] = {}; printf("Enter message => "); int c = 0; while (c < ' ' || 0x7E < c) c = getc(stdin); ungetc(c, stdin); for (int i = 0; i < sizeof(message) - 1 && (c = getc(stdin)) >= ' '; i++) message[i] = c; int i1, i2, i3, i4; printf("UDP receiver address => "); scanf("%d.%d.%d.%d", &i1, &i2, &i3, &i4); for (int i = 0;; i++) { printf("Sending message : %s (%d)\n", message, i); datagram.printf("(%d) %s\n", i, message); char ip[16] = {}; sprintf(ip, "%d.%d.%d.%d", i1, i2, i3, i4); datagram.send(ip, 7777); wait(1); } }