资源描述:
《java网络编程49522》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Java语言程序设计马皓mah@pku.edu.cn1概述URL应用Socket应用UDP数据报第十章Java网络编程2概述TheJavaplatformishighlyregardedinpartbecauseofitssuitabilityforwritingprogramsthatuseandinteractwiththeresourcesontheInternetandtheWorldWideWeb.3概述AppletApplet程序嵌在HTML文件中,通过网络下载Applet程序代码,在本地Java-enabledbrowser中执行HTTP通
2、过URL类获取服务器端的HTML文件Socket(套接字)实现Client/Server结构的应用JDBC(JavaDatabaseConnectivity)通过网络访问关系型数据库Oracle,MSSQL,SybaseServlet/JSP(JavaServerPage)WEB服务器端的动态编程4概述网络基础-TCP/IP协议簇网络层(NetworkLayer)InternetProtocol(IP),IP地址,32比特传输层(TransportLayer)传输控制协议(TCP:TransportControlProtocol)用户数据报协议(UDP:
3、UserDatagramProtocol)端口(Port,16比特,0~65535)应用层(ApplicationLayer)HTTP,FTP,SMTP,POP3,Telnet,DNSTCPorUDPPort应用PortPortPortPort数据1应用应用应用Port数据2主机5概述Java语言中基本网络类Packagejava.netjava.net.URLjava.net.URLConnectionjava.net.Socketjava.net.ServerSocketjava.net.DatagramPacketjava.net.Datagram
4、Socketjava.net.MulticastSocket6概述URL应用Socket应用UDP数据报第十章Java网络编程7URL应用什么是URL?统一资源定位符(UniformResourceLocator)areference(anaddress,apointer)toaresourceontheInternet.httpjava.sun.com://协议标识符资源名(主机名,端口号,文件名)httpwww.pku.edu.cn/index.html://ftpftp.pku.edu.cn/pub/://8URL应用java.net.URL类构造
5、方法publicURL(Stringspec)throwsMalformedURLExceptionpublicURL(Stringprotocol,Stringhost,Stringfile)throwsMalformedURLExceptionpublicURL(Stringprotocol,Stringhost,intport,Stringfile)throwsMalformedURLException……实例方法publicfinalInputStreamopenStream()throwsIOExceptionOpensaconnectiont
6、othisURLandreturnsanInputStreamforreadingfromthatconnectionpublicURLConnectionopenConnection()throwsIOExceptionReturnsaURLConnectionobjectthatrepresentsaconnectiontotheremoteobjectreferredtobytheURL9URL应用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应用实例importjava.net.*;importjava.io.*;publicclassURLReader{publicstaticvoidmain(String[]args)throw
8、sException{URLpku=newURL("http://www.pku