第十三章 Java網(wǎng)絡(luò)編程.ppt_第1頁
第十三章 Java網(wǎng)絡(luò)編程.ppt_第2頁
第十三章 Java網(wǎng)絡(luò)編程.ppt_第3頁
第十三章 Java網(wǎng)絡(luò)編程.ppt_第4頁
第十三章 Java網(wǎng)絡(luò)編程.ppt_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Java Networking Programing,URL,What Is a URL? Definition: URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.,:8080/index.html#Musics,URL,Creating a URL URL gamelan = new URL(,URL(URL baseURL, String relativeURL),URL gamelan = new URL( URL ga

2、melanGames = new URL(gamelan, Gamelan.game.html); URL gamelanNetwork = new URL(gamelan, G.html);,URL(String absoluteURL),URL gamelan = new URL( http, , 80, “pages/Gwork.html); This creates a URL object for the following URL: :80/pages/Gwork.html,MalformedURLException,try URL myURL = new URL(. . .) c

3、atch (MalformedURLException e) . . . / exception handler code here ,Parsing a URL,getProtocol Returns the protocol identifier component of the URL. getHost Returns the host name component of the URL. getPort Returns the port number component of the URL. The getPort method returns an integer that is

4、the port number. If the port is not set, getPort returns -1. getFile Returns the filename component of the URL. getRef Returns the reference component of the URL.,Heres the output displayed by the program: protocol = http host = filename = /docs/books/tutorial/index.html port = 80 ref = DOWNLOADING,

5、Reading Directly from a URL,Connecting to a URL,Reading from a URLConnection,Writing to a URLConnection,Sockets,Sometimes your programs require lower-level network communication. for example, when you want to write a client-server application. To communicate, the client and the server each reads fro

6、m and writes to the socket bound to the connection.,What Is a Socket?,Definition: A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be se

7、nt.,What Is a Socket?,Reading from and Writing to a Socket,This client program is straightforward and simple because the Echo server implements a simple protocol. The client sends text to the server, and the server echoes it back. When your client programs are talking to a more complicated server su

8、ch as an HTTP server, your client program will also be more complicated. However, the basics are much the same as they are in this program: Open a socket. Open an input stream and output stream to the socket. Read from and write to the stream according to the servers protocol. Close the streams. Clo

9、se the socket.,All About Datagrams,Some applications that you write to communicate over the network will not require the reliable, point-to-point channel provided by TCP. Rather, your applications might benefit from a mode of communication that delivers independent packages of information whose arri

10、val and order of arrival are not guaranteed. The UDP protocol provides a mode of network communication whereby applications send packets of data, called datagrams, to one another. A datagram is an independent, self-contained message sent over the network whose arrival, arrival time, and content are

11、not guaranteed. The DatagramPacket and DatagramSocket classes in the package implement system-independent datagram communication using UDP.,What Is a Datagram? Writing a Datagram Client and Server Broadcasting to Multiple Recipients,What Is a Datagram?,Clients and servers that communicate via a reli

12、able channel, such as a URL or a socket, have a dedicated point-to-point channel between themselves, or at least the illusion of one. To communicate, they establish a connection, transmit the data, and then close the connection. All data sent over the channel is received in the same order in which i

13、t was sent. This is guaranteed by the channel. In contrast, applications that communicate via datagrams send and receive completely independent packets of information. These clients and servers do not have and do not need a dedicated point-to-point channel. The delivery of datagrams to their destinations is not guaranteed. Nor is the order of their arrival. Definition: A datagram

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論