Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of lwip by
main.cpp
00001 #include "mbed.h" 00002 #include "TCPCallbackConnection.h" 00003 #include "NetServer.h" 00004 #include "iputil.h" 00005 00006 DigitalOut led(LED1); 00007 00008 /* Every time called if a packet is received for a */ 00009 /* TCPConnection which registerd this Callback. */ 00010 err_t recv_callback(TCPCallbackConnection *arg, struct pbuf *p, err_t err) { 00011 printf("recv_callback\n"); 00012 if(p==NULL) { 00013 printf("Connection closed by server!\n"); 00014 delete arg; 00015 return ERR_OK; 00016 } 00017 00018 while(p) { 00019 char * ch = (char*)p->payload; 00020 printf("\n>>>>>>>>>>>>\n"); 00021 for(int i=0; i < p->len; i++) { 00022 printf("%c", ch[i]); 00023 } 00024 printf("\n<<<<<<<<<<<<\n"); 00025 p = p->next; 00026 } 00027 arg->recved(p->tot_len); 00028 pbuf_free(p); 00029 return ERR_OK; 00030 } 00031 00032 /* Connection etablished, lets try to get a http page */ 00033 err_t connected_callback(TCPCallbackConnection *arg, err_t err) { 00034 printf("Connected Callback!\n"); 00035 char msg[] = "GET / HTTP/1.1\r\nHost: 10.1.129.90\r\n\r\n"; 00036 if(arg->write(msg, strlen(msg)) != ERR_OK) { 00037 error("Could not write", 0); 00038 } 00039 return ERR_OK; 00040 } 00041 struct ip_addr ipa = ipv4addr(209,85,229,99); 00042 int main(void) { 00043 struct ip_addr ipa = ipv4addr(209,85,229,99); 00044 00045 TCPCallbackConnection *con = new TCPCallbackConnection( 00046 ipa, 80, NO_SENT_FNC, &recv_callback, 00047 NO_POLL_FNC, &connected_callback, NO_ERR_FNC 00048 ); 00049 con->connect(); 00050 00051 printf("entering while loop\n"); 00052 while(1) { 00053 led = !led; 00054 NetServer::poll(); 00055 wait(0.1); 00056 } 00057 } 00058
Generated on Tue Jul 12 2022 16:07:06 by
1.7.2
