<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于PXA270嵌入式系統(tǒng)的Socket通信設(shè)計(jì)

          基于PXA270嵌入式系統(tǒng)的Socket通信設(shè)計(jì)

          作者: 時(shí)間:2009-05-18 來(lái)源:網(wǎng)絡(luò) 收藏

          客戶(hù)端與服務(wù)器端進(jìn)程的作用是非對(duì)稱(chēng)的,因此編碼不同。同時(shí),服務(wù)器進(jìn)程一般是先于客戶(hù)請(qǐng)求請(qǐng)求而啟動(dòng)的,只要運(yùn)行,該服務(wù)進(jìn)程一直存在,直到正常或強(qiáng)迫終止。服務(wù)器端主要程序如下:
          mysocket=socket(AF_INET,SOCK_STREAM,0);
          //建立新的套接字
          if(mysocket==-1)
          printf(error!!! failed to created mysocketn);
          return(0); //socket建立不成功,回初始位置
          mybindcheck=bind(mysocket,(struct sockaddr*)addr_local,sizeof(struct sockaddr));
          if(mybindcheck==-1)
          printf(error!!!failed to bind the IP and port with mysocketn);
          return(0);

          本文引用地址:http://www.ex-cimer.com/article/152489.htm

          圖4 服務(wù)器端程序簡(jiǎn)單示意圖
          { printf(OK--you have successed bind your IP with port %dn,port);
          listencheck=listen(mysocket,howmany);
          if(listencheck==-1)
          printf(error!!! you have failed listen this port,program end heren);
          return(0); //調(diào)用監(jiān)聽(tīng)函數(shù)
          sin_size=sizeof(struct sockaddr_in);
          newsocket=accept(mysocket,(struct sockaddr*)addr_remote,sin_size);
          //調(diào)用接收函數(shù)
          if(newsocket==-1)
          printf(error!!!failed to got remote connect this server,program end heren);
          return(0); //建立新的socket失敗返回
          printf(OK-- now have created the newsocket to use this own connection,use this communicate with clint%sn,inet_ntoa(addr_remote.sin_addr),port);
          printf(OK-- server have successed got connect from clint IP = %s,port = %d,now connecting is running;n,inet_ntoa(addr_remote.sin_addr),port)
          pid_t pid;
          pid=fork(); //調(diào)用fork()建立子進(jìn)程
          if(pid>0)
          printf(OK-- i am a father procces,child proccess will continue for you,it's ID= %d,now end newsock and use old socket to listen again................. n,pid);
          close(newsocket);
          printf(OK-- i am a child procces,i am responsible for this new communicate,blow i will do for connectn);
          printf(OK-- please enter your data which you want to send n);
          while(1)
          bzero(sendbuffer,long);
          scanf(%s,sendbuffer);
          sendcheck=send(newsocket,sendbuffer,strlen(sendbuffer),0); //發(fā)送數(shù)據(jù)
          if(sendcheck==-1)
          printf(error!!!failed to send to remoten);
          close(newsocket);
          else
          printf(OK--now you have send %d byte data to remote!!!pleases send again!!!!n,sendcheck);

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

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




          評(píng)論


          相關(guān)推薦

          技術(shù)專(zhuān)區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();