|
发表于 2011-10-8 11:32:18
|
显示全部楼层
这个是TCP的
{
struct netconn *conn, *newconn = NULL;
struct netbuf *TCPNetbuf;
UARTprintf("TCP_Test_task\n");
conn = netconn_new(NETCONN_TCP); /* 创建TCP连接 */
netconn_bind(conn,NULL,80); /* 绑定本地地址和监听的端口号 */
netconn_listen(conn); /* 进入监听状态 */
while(1)
{
newconn = netconn_accept(conn); /*阻塞当前进程到有数据接收 */
if(newconn != NULL)
{
if((TCPNetbuf = netconn_recv(newconn)) != NULL)
{
netconn_write(newconn,(void *)http_html_hdr,sizeof(http_html_hdr),NETCONN_NOCOPY);
/* 发送头部数据 */
netconn_write(newconn,(void *)indexdata,sizeof(indexdata),NETCONN_NOCOPY);
/* 发送实际的WEB页面 */
netbuf_delete(TCPNetbuf);
}
netconn_close(newconn); /* 关闭连接 */
while(netconn_delete(newconn) != ERR_OK)
OSTimeDlyHMSM(0, 0, 1, 0);
}
}
} |
|