在用LWIP协议栈时,有三种方式可以建立一个网络链接:1.用TCP,UDP模块提供的RAW函数 2.使用NETCONN API 3,使用SOCKET API。在这里以《神舟王以太网httpserver网页实验(神舟王STM32F207ZGT-库函数版本)》为例进行说明。这是在stm32裸机上运行lwip的一个例子。在httpd.c文件里面有这么一段程序,如下:
/**
* Initialize the httpd with the specified local address.
*/
static void httpd_init_addr(struct ip_addr *local_addr)
{
struct tcp_pcb *pcb;
err_t err;
pcb = tcp_new();
LWIP_ASSERT("httpd_init: tcp_new failed", pcb != NULL);
tcp_setprio(pcb, HTTPD_TCP_PRIO);
/* set SOF_REUSEADDR here to explicitly bind httpd to multiple interfaces */
err = tcp_bind(pcb, local_addr, HTTPD_SERVER_PORT);
LWIP_ASSERT("httpd_init: tcp_bind failed", err == ERR_OK);
pcb = tcp_listen(pcb);
LWIP_ASSERT("httpd_init: tcp_listen failed", pcb != NULL);
/* initialize callba
/**
* Initialize the httpd with the specified local address.
*/
static void httpd_init_addr(struct ip_addr *local_addr)
{
struct tcp_pcb *pcb;
err_t err;
pcb = tcp_new();
LWIP_ASSERT("httpd_init: tcp_new failed", pcb != NULL);
tcp_setprio(pcb, HTTPD_TCP_PRIO);
/* set SOF_REUSEADDR here to explicitly bind httpd to multiple interfaces */
err = tcp_bind(pcb, local_addr, HTTPD_SERVER_PORT);
LWIP_ASSERT("httpd_init: tcp_bind failed", err == ERR_OK);
pcb = tcp_listen(pcb);
LWIP_ASSERT("httpd_init: tcp_listen failed", pcb != NULL);
/* initialize callba