資源描述:
《java網(wǎng)絡(luò)編程49522》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、Java語言程序設(shè)計馬皓mah@pku.edu.cn1概述URL應(yīng)用Socket應(yīng)用UDP數(shù)據(jù)報第十章Java網(wǎng)絡(luò)編程2概述TheJavaplatformishighlyregardedinpartbecauseofitssuitabilityforwritingprogramsthatuseandinteractwiththeresourcesontheInternetandtheWorldWideWeb.3概述AppletApplet程序嵌在HTML文件中,通過網(wǎng)絡(luò)下載Applet程序代碼,在本地Java-enabledbrowser中執(zhí)行HTTP通
2、過URL類獲取服務(wù)器端的HTML文件Socket(套接字)實現(xiàn)Client/Server結(jié)構(gòu)的應(yīng)用JDBC(JavaDatabaseConnectivity)通過網(wǎng)絡(luò)訪問關(guān)系型數(shù)據(jù)庫Oracle,MSSQL,SybaseServlet/JSP(JavaServerPage)WEB服務(wù)器端的動態(tài)編程4概述網(wǎng)絡(luò)基礎(chǔ)-TCP/IP協(xié)議簇網(wǎng)絡(luò)層(NetworkLayer)InternetProtocol(IP),IP地址,32比特傳輸層(TransportLayer)傳輸控制協(xié)議(TCP:TransportControlProtocol)用戶數(shù)據(jù)報協(xié)議(UDP:
3、UserDatagramProtocol)端口(Port,16比特,0~65535)應(yīng)用層(ApplicationLayer)HTTP,FTP,SMTP,POP3,Telnet,DNSTCPorUDPPort應(yīng)用PortPortPortPort數(shù)據(jù)1應(yīng)用應(yīng)用應(yīng)用Port數(shù)據(jù)2主機5概述Java語言中基本網(wǎng)絡(luò)類Packagejava.netjava.net.URLjava.net.URLConnectionjava.net.Socketjava.net.ServerSocketjava.net.DatagramPacketjava.net.Datagram
4、Socketjava.net.MulticastSocket6概述URL應(yīng)用Socket應(yīng)用UDP數(shù)據(jù)報第十章Java網(wǎng)絡(luò)編程7URL應(yīng)用什么是URL?統(tǒng)一資源定位符(UniformResourceLocator)areference(anaddress,apointer)toaresourceontheInternet.httpjava.sun.com://協(xié)議標識符資源名(主機名,端口號,文件名)httpwww.pku.edu.cn/index.html://ftpftp.pku.edu.cn/pub/://8URL應(yīng)用java.net.URL類構(gòu)造
5、方法publicURL(Stringspec)throwsMalformedURLExceptionpublicURL(Stringprotocol,Stringhost,Stringfile)throwsMalformedURLExceptionpublicURL(Stringprotocol,Stringhost,intport,Stringfile)throwsMalformedURLException……實例方法publicfinalInputStreamopenStream()throwsIOExceptionOpensaconnectiont
6、othisURLandreturnsanInputStreamforreadingfromthatconnectionpublicURLConnectionopenConnection()throwsIOExceptionReturnsaURLConnectionobjectthatrepresentsaconnectiontotheremoteobjectreferredtobytheURL9URL應(yīng)用java.net.URL類-示例“http://www.pku.cn/”newURL("http://www.pku.cn");http://www.p
7、ku.cn/academic/index.htmlnewURL("http://www.pku.cn/academic/index.html");newURL("http","www.pku.cn","/academic/index.html");newURL("http","www.pku.cn",80,“/academic/index.html");10URL應(yīng)用實例importjava.net.*;importjava.io.*;publicclassURLReader{publicstaticvoidmain(String[]args)throw
8、sException{URLpku=newURL("http://www.pku