TCPSocket_Ethernet modify

Dependencies:   EthernetInterface2 mbed-rtos mbed

Fork of TCPSocket_HelloWorld by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 
00004 Serial pc(USBTX, USBRX);
00005 
00006 int main() {
00007     EthernetInterface eth;
00008     eth.init(); //Use DHCP
00009     int i = eth.connect();
00010     pc.printf("Connection = %d, ",i);
00011     pc.printf("\nIP Address is %s -\nGateway: %s -\nMACAddress %s \n", eth.getIPAddress(),eth.getGateway(),eth.getMACAddress());
00012     
00013     TCPSocketConnection sock;
00014     sock.connect("www.unife.it", 80);
00015     
00016     char http_cmd[] = "GET /ing/lm.infoauto HTTP/1.0\n\n";
00017     sock.send_all(http_cmd, sizeof(http_cmd)-1);
00018     
00019     char buffer[300];
00020     int ret;
00021     while (true) {
00022         ret = sock.receive(buffer, sizeof(buffer)-1);
00023         if (ret <= 0)
00024             break;
00025         buffer[ret] = '\0';
00026         pc.printf("Received %d chars from server:\n%s\n", ret, buffer);
00027     }
00028       
00029     sock.close();
00030     
00031     eth.disconnect();
00032     
00033     while(1) {}
00034 }