版權(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 職業(yè)指導(dǎo)師崗前崗位安全考核試卷含答案
- 潤(rùn)滑油加氫裝置操作工安全素養(yǎng)知識(shí)考核試卷含答案
- 電子設(shè)備調(diào)試工操作水平模擬考核試卷含答案
- 白酒發(fā)酵工安全專項(xiàng)知識(shí)考核試卷含答案
- 油氣管道維護(hù)工安全生產(chǎn)能力競(jìng)賽考核試卷含答案
- 調(diào)配香精配制工操作水平強(qiáng)化考核試卷含答案
- 2026云南臨滄市桑嘎藝術(shù)學(xué)校教師招聘9人備考題庫完整參考答案詳解
- 《育兒常見問題解答》
- 新生兒皮膚護(hù)理與常見問題處理
- 2026年及未來5年市場(chǎng)數(shù)據(jù)中國(guó)B超診斷儀行業(yè)發(fā)展監(jiān)測(cè)及投資戰(zhàn)略咨詢報(bào)告
- 風(fēng)電項(xiàng)目質(zhì)量管理
- 靜脈輸液操作規(guī)范與并發(fā)癥預(yù)防指南
- 臨床正確標(biāo)本采集規(guī)范
- 福建省福州市福清市2024-2025學(xué)年二年級(jí)上學(xué)期期末考試語文試卷
- 2025年CAR-NK細(xì)胞治療臨床前數(shù)據(jù)
- 班團(tuán)活動(dòng)設(shè)計(jì)
- 基金通道業(yè)務(wù)合同協(xié)議
- 黨參對(duì)人體各系統(tǒng)作用的現(xiàn)代藥理研究進(jìn)展
- 交通銀行理財(cái)合同范本
- 林業(yè)結(jié)構(gòu)化面試題庫及答案
- 肺結(jié)節(jié)的影像學(xué)表現(xiàn)
評(píng)論
0/150
提交評(píng)論