新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 實時操作系統(tǒng)uC/0S II下TCP/IP協(xié)議棧的實現(xiàn)

實時操作系統(tǒng)uC/0S II下TCP/IP協(xié)議棧的實現(xiàn)

作者: 時間:2012-08-21 來源:網(wǎng)絡(luò) 收藏

實用Berkley API的tcpecho_thread是一個TCP echo服務(wù)器,*7號端口,程序框架如下:

void tcpecho_thread(void *arg){

conn = netconn_new(NETCONN_TCP); //創(chuàng)建新的連接標(biāo)識

netconn_bind(conn, NULL, 7); //綁定到7號端口

netconn_listen(conn); //開始*端口

while(1){

newconn = netconn_accept(conn); //接收外部到來的連接

buf = netconn_recv(newconn) //獲取數(shù)據(jù)

……. //處理數(shù)據(jù)

netconn_write(newconn, data, len, NETCONN_COPY); //發(fā)送數(shù)據(jù)

netconn_delete(newconn); //釋放本次連接

}

}

編譯運行后,用ping ip地址命令可以得到ICMP reply響應(yīng)。用telnet ip地址 7(登錄7號端口)命令可以看到echo server的回顯效果。說明ARP、ICMP、IP、TCP都已正確運行。

linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)

c語言相關(guān)文章:c語言教程


linux相關(guān)文章:linux教程


tcp/ip相關(guān)文章:tcp/ip是什么



上一頁 1 2 3 下一頁

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉