新聞中心

        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]='

        主站蜘蛛池模板: 石楼县| 东海县| 天津市| 临武县| 无为县| 伊春市| 西昌市| 洮南市| 名山县| 东丽区| 阿拉善右旗| 彝良县| 泸水县| 凉山| 鄯善县| 杨浦区| 温州市| 尚志市| 莲花县| 绥化市| 林口县| 北川| 江达县| 奉节县| 河源市| 苍山县| 凌源市| 祁连县| 仁寿县| 敦化市| 阿克苏市| 卢湾区| 梁平县| 阿荣旗| 师宗县| 崇明县| 和平县| 普兰县| 湾仔区| 潞城市| 阜新市|