A http client sample program.
Dependencies: NyFileSystems libMiMic mbed-rtos mbed
Fork of TcpSocketClientSamlpe by
main.cpp
- Committer:
- nyatla
- Date:
- 2013-10-03
- Revision:
- 26:f58dc24e2c1b
- Parent:
- 25:1a4f620b7af6
- Child:
- 28:dd350a9a5221
File content as of revision 26:f58dc24e2c1b:
/** * @file * TCP client socket sample.<br/> * This program is to test of TCP client. * Connect to a TCP server, and send back the received data as is. * */ #include "mbed.h" #include "rtos.h" #include "SDFileSystem.h" #include "mimic.h" #include "utils/PlatformInfo.h" #include "fsdata.h" LocalFileSystem2 lf("local"); NetConfig cfg; //create network configulation Net* net; DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); int main() { net=new Net();//Net constructor must be created after started RTOS // manual setting cfg.setIpAddr(192,168,128,39); cfg.setNetMask(255,255,255,0); cfg.setGateway(192,168,128,254); cfg.setSrvUPnP(false); cfg.setSrvMdns(false); // Create http client. // Socket must create between "net.start" with "new Net()" HttpClient http; //Start network net->start(cfg); if(http.connect(IpAddr(192,168,128,195),80)){ if(http.sendMethod(HttpClient::HTTP_GET,"/mimic/")){ FILE *fp=fopen("/local/out.txt", "w"); if(fp!=NULL){ int s=http.getStatus(); fprintf(fp, "Status:%d\n",s); if(s==200){ for(;;){ short l; char b[32]; if(!http.read(b,32,l)){ //Error led1=1; break; } if(fwrite(b,1,l,fp)<l){ //EOS led2=1; break; } if(l==0){ //EOS led3=1; break; } } } fclose(fp); } } http.close(); } for(int c=0;;c=(c+1)%2){ led4=c; Thread::wait(500); } return 0; }