参照的时V7-2001_LwIP V2.X_实验_工程移植模板(FreeRTOS)V1.1,具体参照的代码如下:
[C] 纯文本查看 复制代码 void LwIPTest(void)
{
struct netconn *conn, *newconn;
err_t err;
/* 创建服务器 */
conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, IP_ADDR_ANY, PORT_NUM);
/* 设置监听 */
netconn_listen(conn);
while (1)
{
/* 等待接收新的连接 */
err = netconn_accept(conn, &newconn);
/* 处理新连接 */
if (err == ERR_OK)
{
struct netbuf *buf;
void *data;
u16_t len;
/* 简单的数据回环 */
while ((err = netconn_recv(newconn, &buf)) == ERR_OK)
{
do {
netbuf_data(buf, &data, &len);
err = netconn_write(newconn, data, len, NETCONN_COPY);
} while (netbuf_next(buf) >= 0);
netbuf_delete(buf);
}
/* 删除连接 */
netconn_close(newconn);
netconn_delete(newconn);
}
}
}
|