1
Dependencies: EthernetInterface mbed-rtos mbed
main.cpp
- Committer:
- yu10078999
- Date:
- 2016-09-11
- Revision:
- 1:b1506df02fe6
- Parent:
- 0:ea9c19e28331
- Child:
- 2:807d696cf266
File content as of revision 1:b1506df02fe6:
#include "mbed.h" #include "EthernetInterface.h" #include "TCPSocketConnection.h" EthernetInterface eth; RawSerial pc(USBTX, USBRX); // tx, rx int main() { pc.baud(9600); eth.init(); //Use DHCP eth.connect(); printf("IP Address is %s \n\r", eth.getIPAddress()); TCPSocketConnection socket; socket.connect("httpbin.org", 80); char http_cmd[] = "GET /get?helloworld HTTP/1.0\r\n\r\n"; socket.send_all(http_cmd, sizeof(http_cmd)-1); char buffer[300]; int ret; while (true) { ret = socket.receive(buffer, sizeof(buffer)-1); if (ret <= 0) break; buffer[ret] = '\0'; printf("Received %d chars from server:\n%s\n", ret, buffer); } printf("DONE!\n"); socket.close(); eth.disconnect(); while(1) {} }