I am using Tm4c 129 exl board, I am trying to show a tiny site on the launchpad, but the board is not working, after I get the Ip and bind the site. I set the break point in the code, and found that the string is actually send out by the board when the website ip address in the browser.
This code was found online, and it compile well, I got two question here.
1. for the Tcp_write() it should has a tcp_receive() at there other end of the ethernet connection, is the http browser is some kind of tcp_receive()?
2. The web site data were sent two parts. first http header, second index data, can you guys help me understand a basic idea of the file? how it works, as far as I can seen from the code, the website info were sent out as strings, how the string data became a website?
Thanks
Shan
/*************************TCP Web site***********************/ const static uint8_t indexdata[]="<!DOCTYPE html>\n" "<html>\n" "<head>\n" "<title>Title of the document</title>\n" "</head>\n" "\n" "<body>\n" "The content of the document......\n" "</body>\n" "\n" "</html>"; const static uint8_t http_html_hdr []="HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n"; /******************* call back function*****************/ static err_t http_recv(void *arg, struct tcp_pcb *pcb,struct pbuf *p,err_t err) { if(p != NULL) { tcp_write(pcb,http_html_hdr,sizeof(http_html_hdr),0); tcp_write(pcb,indexdata,sizeof(indexdata),0); pbuf_free(p); } tcp_close(pcb); err = ERR_OK; return err; } /**********************这call back function when the connection is bindded**********************/ static err_t http_accept(void *arg,struct tcp_pcb *pcb,err_t err) { tcp_setprio(pcb, TCP_PRIO_MIN); tcp_recv(pcb,http_recv); err = ERR_OK; return err; } void http_init(void) { struct tcp_pcb *pcb; pcb = tcp_new(); tcp_bind(pcb,IP_ADDR_ANY,80); pcb = tcp_listen(pcb); tcp_accept(pcb,http_accept); }