資源描述:
《無(wú)人機(jī)網(wǎng)絡(luò)通信TCPIP協(xié)議》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、專業(yè)移動(dòng)應(yīng)用開(kāi)發(fā)學(xué)號(hào)—姓名實(shí)驗(yàn)報(bào)告班級(jí)16移動(dòng)應(yīng)用(1)成績(jī)?cè)u(píng)定小組編號(hào)—號(hào)教師簽名實(shí)驗(yàn)內(nèi)容第周星期二第11—12節(jié)、實(shí)驗(yàn)?zāi)康呐c要求1.了解物聯(lián)網(wǎng)應(yīng)用2.了解網(wǎng)絡(luò)通信TCP/IP協(xié)議3.掌握網(wǎng)絡(luò)通信客戶端實(shí)現(xiàn)方法二、實(shí)驗(yàn)環(huán)境及方案Windows操作系統(tǒng)和Android開(kāi)發(fā)集成環(huán)境三、實(shí)驗(yàn)步驟(一)、認(rèn)識(shí)無(wú)人機(jī)硬件1、分發(fā)無(wú)人機(jī)并詳細(xì)講解其硬件組成2、指導(dǎo)各小組找到自己小組的無(wú)人機(jī)wifi3、項(xiàng)目技術(shù)結(jié)合行業(yè)分析(二)、安卓網(wǎng)絡(luò)通信客戶端的實(shí)現(xiàn)1、TCP/IP通信協(xié)議2、網(wǎng)絡(luò)通信服務(wù)端與客戶端的實(shí)現(xiàn)步驟①創(chuàng)建Java類服務(wù)端0Serverjava23xo?/14pu
2、blicclassServer{is-publicstaticvoidmain(String[]args){16try{17//2?創(chuàng)建服務(wù)端的Sock嘰BPServerSocket,指定綁定夠口,并監(jiān)聽(tīng)此端口18Serversocketserversocket=newServersocket(8888);19System?out?printIn(”等待客戶端的連接“);20//2?調(diào)用@£釵1()方法開(kāi)始監(jiān)聽(tīng),等待容戶端的連接21Socketsocket■serversocket?accept();22//3?獲取輸入流,并讀取容戶端信息23Inputstrea
3、mis-socket.getInputStream();//字節(jié)輸入流24InputStreamReaderinputStreamReader=newInputStrearaReader(is);//將字節(jié)流轉(zhuǎn)換為宇符流25BufferedReaderbufferedReader■newBufferedReader(inputStreamReader);//為輸入流潘加緩沖26//循環(huán)讀取容戶券的信息27Stringmsg■null;28while((msg=bufferedReader.readLine())!=null){29System.out?printi
4、ng容丹■msg);30}31//關(guān)閉偷入茨32socket?shutdowninput();33//4?關(guān)閉資源34bufferedReader?dose();35inputStreamReader?close();36is?close();37socket?close();38serversocket?close();3940}catch(IOExceptione){//TODOAuto-generatedcatchblocki44}e.printStackTrace();}}②創(chuàng)建Java類客戶端E)Clientjava卻12*/1314publicclas
5、sClient{15&publicstaticvoidmain(St廠ing[]args){@1617//TODOAuto-generatedmethodstub18try{19//1?創(chuàng)建客戶端socket,指定服務(wù)器地址和端口20Sockets=newSocket(wlocalhostM,8888);21//2.獲取輸出流,想服務(wù)器端發(fā)送信息22Outputstreamos=s.getOutputStream();//字節(jié)輸出流23Printwriterpw=newPrintWriter(os〉;//將輸也流包女為打印流24pw.write(Mhahan);2
6、5pw.flush();2627s?Shutdownoutput();//關(guān)閉輸出流28/門?關(guān)閉資源29pw.close();30os.close();31s.close();32}catch(UnknownHostExceptione){園33//TODOAuto-generatedcatchblock34e.printStackTrace();35}catch(IOExceptione){園36//TODOAuto-generatedcatchblock37e?printStackTrace();3839}4041}42}㈢、、連接無(wú)人機(jī)1、解讀通信協(xié)議中安
7、卓客戶端的注意事項(xiàng)2、根據(jù)通信步驟實(shí)現(xiàn)客戶端和無(wú)人機(jī)的連接%1添加網(wǎng)絡(luò)網(wǎng)絡(luò)權(quán)限Q連接無(wú)人機(jī)Manifest-1k?xmlversion^.0Mencoding?Mwty-SM?>6789ie1113€>1415161718^192021?22232425262'〈uses?sdlc
8、andro