新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 基于PXA270嵌入式系統的Socket通信設計

        基于PXA270嵌入式系統的Socket通信設計

        作者: 時間:2009-05-18 來源:網絡 收藏

        3.1 客戶端程序
        客戶端可以向服務器端發送連接請求,并且客戶端也可以接收到來自服務器端發送回來的數據。客戶端可以判斷當前自己的工作狀態,如連接的建立,啟動的成功和數據包的個數等。客戶端程序主要按以下的步驟完成函數的調用:
        ①建立自己的(并驗證建立成功);
        ②啟動連接(并驗證建立成功);
        ③返回連接信息;
        ④接收收到的數據;
        ⑤判斷數據的屬性。
        客戶端程序的程序基本流程如圖3所示。

        本文引用地址:http://www.104case.com/article/152489.htm

        圖3 客戶端程序簡單示意圖
        客戶端打開通道,并連接到服務器所在主機的特定端口,向服務器發送請求報文,等待并接收應答,請求結束后關閉通道并終止通信。客戶端主要程序如下:
        Int main(int argc,char *argv[])
        if(argc!=3)
        printf(error!!!please enter the remote IP and PORT please!!! the form like 192.168.0.* 4000n);
        mysocket=socket(AF_INET,SOCK_STREAM,0); //建立一個套接字
        if(mysocket==-1)
        printf(error!!! failed to created the new socket,program end heren);
        printf(OK-- you have successful created a socket named mysocketn);
        return(0); //socket 建立不成功,回初始位置
        connectcheck=connect(mysocket,(struct sockaddr*)addr_remote,sizeof(struct sockaddr));
        //調用connect函數連接服務器端
        if(connectcheck==-1)
        printf(error!!!sorry you have failed to connect the remote server!!try again !program end heren);
        // connect不成功回初始位置
        printf(OK-- Now you have successful connect the server,this server IP =%s,and it's PORT =%s,now you can communicat with this server!!!!!!!n ,argv[1],argv[2])
        //打印服務器IP地址和端口號
        while(1)
        bzero(gotbuffer,long);
        number=recv(mysocket,gotbuffer,long,0);
        //調用阻塞函數
        if(number==-1)
        printf(error!!! some thing wrong !let you can not got the data form server,program end heren);
        return(0);
        gotbuffer[number]='

        主站蜘蛛池模板: 浦北县| 合山市| 西盟| 桑植县| 绥芬河市| 花莲县| 象州县| 阿克| 汾阳市| 彭山县| 岫岩| 库伦旗| 响水县| 康平县| 齐河县| 莱芜市| 德州市| 鞍山市| 翼城县| 巨鹿县| 黔西| 犍为县| 永福县| 西充县| 资兴市| 胶州市| 通州区| 岐山县| 淮滨县| 翁牛特旗| 三江| 新乡县| 景泰县| 大足县| 鲜城| 福建省| 梅州市| 区。| 阳城县| 弋阳县| 萨嘎县|