f

Dependencies:   mbed

Fork of lwip by mbed unsupported

Committer:
idijoeteque
Date:
Thu Aug 03 10:24:16 2017 +0000
Revision:
1:803fdc96fbd7
Parent:
0:5e1631496985
hello

Who changed what in which revision?

UserRevisionLine numberNew contents of line
root@mbed.org 0:5e1631496985 1 #include "mbed.h"
root@mbed.org 0:5e1631496985 2 #include "TCPCallbackConnection.h"
root@mbed.org 0:5e1631496985 3 #include "NetServer.h"
root@mbed.org 0:5e1631496985 4 #include "iputil.h"
root@mbed.org 0:5e1631496985 5
root@mbed.org 0:5e1631496985 6 DigitalOut led(LED1);
root@mbed.org 0:5e1631496985 7
root@mbed.org 0:5e1631496985 8 /* Every time called if a packet is received for a */
root@mbed.org 0:5e1631496985 9 /* TCPConnection which registerd this Callback. */
root@mbed.org 0:5e1631496985 10 err_t recv_callback(TCPCallbackConnection *arg, struct pbuf *p, err_t err) {
root@mbed.org 0:5e1631496985 11 printf("recv_callback\n");
root@mbed.org 0:5e1631496985 12 if(p==NULL) {
root@mbed.org 0:5e1631496985 13 printf("Connection closed by server!\n");
root@mbed.org 0:5e1631496985 14 delete arg;
root@mbed.org 0:5e1631496985 15 return ERR_OK;
root@mbed.org 0:5e1631496985 16 }
root@mbed.org 0:5e1631496985 17
root@mbed.org 0:5e1631496985 18 while(p) {
root@mbed.org 0:5e1631496985 19 char * ch = (char*)p->payload;
root@mbed.org 0:5e1631496985 20 printf("\n>>>>>>>>>>>>\n");
root@mbed.org 0:5e1631496985 21 for(int i=0; i < p->len; i++) {
root@mbed.org 0:5e1631496985 22 printf("%c", ch[i]);
root@mbed.org 0:5e1631496985 23 }
root@mbed.org 0:5e1631496985 24 printf("\n<<<<<<<<<<<<\n");
root@mbed.org 0:5e1631496985 25 p = p->next;
root@mbed.org 0:5e1631496985 26 }
root@mbed.org 0:5e1631496985 27 arg->recved(p->tot_len);
root@mbed.org 0:5e1631496985 28 pbuf_free(p);
root@mbed.org 0:5e1631496985 29 return ERR_OK;
root@mbed.org 0:5e1631496985 30 }
root@mbed.org 0:5e1631496985 31
root@mbed.org 0:5e1631496985 32 /* Connection etablished, lets try to get a http page */
root@mbed.org 0:5e1631496985 33 err_t connected_callback(TCPCallbackConnection *arg, err_t err) {
root@mbed.org 0:5e1631496985 34 printf("Connected Callback!\n");
root@mbed.org 0:5e1631496985 35 char msg[] = "GET / HTTP/1.1\r\nHost: 10.1.129.90\r\n\r\n";
root@mbed.org 0:5e1631496985 36 if(arg->write(msg, strlen(msg)) != ERR_OK) {
root@mbed.org 0:5e1631496985 37 error("Could not write", 0);
root@mbed.org 0:5e1631496985 38 }
root@mbed.org 0:5e1631496985 39 return ERR_OK;
root@mbed.org 0:5e1631496985 40 }
idijoeteque 1:803fdc96fbd7 41 struct ip_addr ipa = ipv4addr(209,85,229,99);
root@mbed.org 0:5e1631496985 42 int main(void) {
root@mbed.org 0:5e1631496985 43 struct ip_addr ipa = ipv4addr(209,85,229,99);
root@mbed.org 0:5e1631496985 44
root@mbed.org 0:5e1631496985 45 TCPCallbackConnection *con = new TCPCallbackConnection(
root@mbed.org 0:5e1631496985 46 ipa, 80, NO_SENT_FNC, &recv_callback,
root@mbed.org 0:5e1631496985 47 NO_POLL_FNC, &connected_callback, NO_ERR_FNC
root@mbed.org 0:5e1631496985 48 );
root@mbed.org 0:5e1631496985 49 con->connect();
root@mbed.org 0:5e1631496985 50
root@mbed.org 0:5e1631496985 51 printf("entering while loop\n");
root@mbed.org 0:5e1631496985 52 while(1) {
root@mbed.org 0:5e1631496985 53 led = !led;
root@mbed.org 0:5e1631496985 54 NetServer::poll();
root@mbed.org 0:5e1631496985 55 wait(0.1);
root@mbed.org 0:5e1631496985 56 }
root@mbed.org 0:5e1631496985 57 }
root@mbed.org 0:5e1631496985 58