hi

Dependencies:   EthernetInterface mbed-rtos mbed-src

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 int main() {
00005     EthernetInterface eth;
00006     eth.init(); //Use DHCP
00007     eth.connect();
00008     printf("IP Address is %s\n", eth.getIPAddress());
00009     
00010     TCPSocketConnection sock;
00011     sock.connect("http://192.168.0.233/cgi-bin/ext/e_alarm.cgi?zone=0", 80);
00012     
00013     char http_cmd[] = "http://192.168.0.233/cgi-bin/ext/e_alarm.cgi?zone=0";
00014     sock.send_all(http_cmd, sizeof(http_cmd)-1);
00015     
00016     char buffer[300];
00017     int ret;
00018     while (true) {
00019         ret = sock.receive(buffer, sizeof(buffer)-1);
00020         if (ret <= 0)
00021             break;
00022         buffer[ret] = '\0';
00023         printf("Received %d chars from server:\n%s\n", ret, buffer);
00024     }
00025       
00026     sock.close();
00027     
00028     eth.disconnect();
00029     
00030     while(1) {}
00031 }