版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、2: Application Layer,1,DNS: Domain Name System,People: many identifiers: SSN, name, Passport # Internet hosts, routers: IP address (32 bit) - used for addressing datagrams “name”, e.g., - used by humans Q: map between IP addresses and name ?,Domain Name System: distributed database
2、 implemented in hierarchy of many name servers application-layer protocol host, routers, name servers to communicate to resolve names (address/name translation) note: core Internet function implemented as application-layer protocol complexity at networks “edge”,2: Application Layer,2,DNS name server
3、s,no server has all name-to-IP address mappings local name servers: each ISP, company has local (default) name server host DNS query first goes to local name server authoritative name server: for a host: stores that hosts IP address, name can perform name/address translation for that hosts name,Why
4、not centralize DNS? single point of failure traffic volume distant centralized database maintenance doesnt scale!,2: Application Layer,3,DNS: Root name servers,contacted by local name server that can not resolve name root name server: contacts authoritative name server if name mapping not known gets
5、 mapping returns mapping to local name server dozen root name servers worldwide,2: Application Layer,4,Simple DNS example,host surf.eurecom.fr wants IP address of 1. Contacts its local DNS server, dns.eurecom.fr 2. dns.eurecom.fr contacts root name server, if necessary 3. root name
6、 server contacts authoritative name server, , if necessary,requesting host surf.eurecom.fr,,root name server,authorititive name server ,1,2,3,4,5,6,2: Application Layer,5,DNS example,Root name server: may not know authoratiative name server may know interme
7、diate name server: who to contact to find authoritative name server,requesting host surf.eurecom.fr,,root name server,1,2,3,4,5,6,authoritative name server ,7,8,2: Application Layer,6,DNS: iterated queries,recursive query: puts burden of name resolution on contacted
8、name server heavy load? iterated query: contacted server replies with name of server to contact “I dont know this name, but ask this server”,requesting host surf.eurecom.fr,,root name server,1,2,3,4,5,6,authoritative name server ,7,8,iterated query,2: Application Lay
9、er,7,DNS: caching and updating records,once (any) name server learns mapping, it caches mapping cache entries timeout (disappear) after some time update/notify mechanisms under design by IETF RFC 2136 /html.charters/dnsind-charter.html,2: Application Layer,8,DNS records,DNS: distri
10、buted db storing resource records (RR),Type=NS name is domain (e.g. ) value is IP address of authoritative name server for this domain,Type=A name is hostname value is IP address,Type=CNAME name is an alias name for some “cannonical” (the real) name value is cannonical name,Type=MX value is hostname
11、 of mailserver associated with name,2: Application Layer,9,DNS protocol, messages,DNS protocol : query and repy messages, both with same message format,msg header identification: 16 bit # for query, repy to query uses same # flags: query or reply recursion desired recursion available reply is author
12、itative,2: Application Layer,10,DNS protocol, messages,Name, type fields for a query,RRs in reponse to query,records for authoritative servers,additional “helpful” info that may be used,2: Application Layer,11,Socket programming,Socket API introduced in BSD4.1 UNIX, 1981 Now Industry standard Availa
13、ble on many operating systems explicitly created, used, released by apps client/server paradigm two types of transport service via socket API: unreliable datagram reliable, byte stream-oriented,Goal: learn how to build client/server application that communicate using sockets,2: Application Layer,12,
14、What is “socket”?,A socket is a virtual connection between two applications Using a socket, two processes can communicate with each other The socket is the major communication tool for Internet applications A socket is bi-directional (full-duplex) transmission A socket can be created dynamically,2:
15、Application Layer,13,Network,Socket as a virtual connection between two processes,(physical connection),Host B,Process 2,Host A,Process 1,Information Hiding,2: Application Layer,14,Socket as a client/server model,2: Application Layer,15,Socket,OS abstraction (not hardware) Created dynamically Persis
16、ts only while application runs Referenced by a descriptor,2: Application Layer,16,Descriptor,Small integer One per active socket Used in all operations on socket Generated by OS when socket created Only meaningful to application that owns socket In UNIX, integrated with file descriptors,2: Applicati
17、on Layer,17,Creating a Socket,Application calls socket function OS returns descriptor for socket Descriptor valid until application closes socket or exits Common: protofamily = PF_INET, type = SOCK_STREAM,SOCK_DGRAM or SOCK_RAW,desc = socket(protofamily,type,proto);,2: Application Layer,18,Socket Fu
18、nctionality,Socket completely general Can be used By client By server With a CO transport protocol With a CL transport protocol To send data, receive data, or both Large set of operations,2: Application Layer,19,Socket Operations,Close Terminate use of socket Permanent,close(socket);,2: Application
19、Layer,20,Socket Operations,Bind Specify protocol port for a socket Specify local IP address for a socket Can use INADDR_ANY for any IP address,bind(socket,localaddr,addrlen);,2: Application Layer,21,Socket Operations (continued),Listen Used by server Prepares socket to accept incoming connections,li
20、sten(socket,queuesize);,newsock = accept(socket,caddr,caddrlen);,Accept Used by server Waits for next connection and returns new socket,2: Application Layer,22,Socket Operations (continued),Connect Used by client Either Performs a TCP connection Fully specifies addresses for UDP,connect(socket,saddr
21、,saddrlen);,2: Application Layer,23,Socket Operations (continued),Send, sendto, and sndmsg Transfer outgoing data from application,send(socket,data,length,flags);,sendmsg(socket,msgstruct,flags);,sendto(socket,data,length,flags, destaddr,addrlen);,2: Application Layer,24,Format of msgstruct,struct m
22、sgstruct struct sockaddr *m_saddr; /*dest address*/ struct datavec *m_dvec; /*message (vector)*/ int mdvlength; /*size of vector*/ struct access *m_rights; /*access rights*/ int m_alength; /*size of access rights*/ ,2: Application Layer,25,Socket Operations (continued),Recv, recvfrom, and recvmsg Tr
23、ansfer incoming data to application,recv(socket,buffer,length,flags);,recvmsg(socket,msgstruct,flags);,recvfrom(socket,buffer,length,flags, senderaddr,saddrlen);,2: Application Layer,26,Socket Operations (continued),Many additional functions Supply support and utility services Some implemented as li
24、brary calls,2: Application Layer,27,Examples of Socket Support Functions,Gethostbyname Maps domain name to IP address Example of argument Getprotobyname Maps name of protocol to internal number Argument usually “tcp” or “udp”,2: Application Layer,28,SERVER,bind(),listen(),accept()
25、,read(),write(),close(),CLIENT,socket(),connect(),write(),close(),socket(),read(),Socket Programming Tutorial(1),2: Application Layer,29,Functions and parameter format (for server side) (1) create socket: socket_id = socket (AF_INET, SOCK_STREM, DEFAULT_PROTOCOL); (2) bind socket: bind (socket_id, s
26、erver_addr, server_len); (3) listen to socket: listen (socket_id, number_of_connection); (4) accept a connection: accept (socket_id, ,Socket Programming Tutorial(2),2: Application Layer,30,Functions and parameter format (for client side) (1) create socket: same as server socket_id = socket (AF_INET,
27、 SOCK_STREM, DEFAULT_PROTOCOL); (2) connect socket: connect (socket_id, serverINETaddress, server_len); (3) write (send) data: write (socket_id, buffer, buffer_len); (4) read (receive) data: read (socket_id, buffer, buffer_len); (5) close socket: same as server close(socket_id);,Socket Programming T
28、utorial(3),2: Application Layer,31,“*” indicates a blocking function call.,SERVER,bind(),listen(),accept(),read(),CLIENT,socket(),connect(),write(),socket(),*,*,*,1: Connection Request,2. Send a command,3. Receive the result,read(),We are not doing this.,*,Socket Programming Tutorial(4),2: Applicati
29、on Layer,32,Step 1: socket(_) call,It declares a socket to be used.,After socket(_) call:,Socket Programming Tutorial(5),2: Application Layer,33,Step 2: bind(_) call,It connects a process to a specific port,After bind(_) call:,Server,Port Numbers:,01023: System Reserved Port 21: FTP Port 23: telnet
30、Port 80: HTTP,1024 and above: available to users,Port,Socket Programming Tutorial(6),2: Application Layer,34,Step 3: listen(_) call,After listen(_) call:,6500,We need to specify how many connection requests should be held in the buffer when SERVER is busy (cant accept a request).,listen (socket_id,
31、number_of_connection);,Server,Socket Programming Tutorial(7),2: Application Layer,35,Step 4 - Part 1: accept(_) call,The server process accepts a request from a client,After accept(_) call:,Server,6500,Socket Programming Tutorial(8),2: Application Layer,36,Step 4 - Part 2: accept(_) call,The accept(
32、_) call returns another port number and establish another connection,Client,7100,6500,Socket Programming Tutorial(9),2: Application Layer,37,Step 5: read(_) and write() call,Client,7100,The server and client communicate using the second socket,6500,Socket Programming Tutorial(10),2: Application Laye
33、r,38,Step 6: close (_) call,Client,7100,Close the second socket and leave the first socket for next client,6500,Socket Programming Tutorial(11),2: Application Layer,39,Step 7: Go back to accept (_) call,The server process goes back to the accept call,6500,Socket Programming Tutorial(12),2: Applicati
34、on Layer,40,Socket-programming using TCP,Socket: a door between application process and end-end-transport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another,controlled by application developer,controlled by operating system,host or server,controlled by applicat
35、ion developer,controlled by operating system,host or server,internet,2: Application Layer,41,Socket programming with TCP,Client must contact server server process must first be running server must have created socket (door) that welcomes clients contact Client contacts server by: creating client-loc
36、al TCP socket specifying IP address, port number of server process,When client creates socket: client TCP establishes connection to server TCP When contacted by client, server TCP creates new socket for server process to communicate with client allows server to talk with multiple clients,2: Applicat
37、ion Layer,42,Socket programming with TCP,Example client-server app: client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream) server reads line from socket server converts line to uppercase, sends back to client client reads, prints modified line fro
38、m socket (inFromServer stream),Input stream: sequence of bytes into process Output stream: sequence of bytes out of process,2: Application Layer,43,Client/server socket interaction: TCP,Server (running on hostid),Client,2: Application Layer,44,Example: Java client (TCP),import java.io.*; import .*;
39、class TCPClient public static void main(String argv) throws Exception String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in); Socket clientSocket = new Socket(hostname, 6789); DataOutputStream outToServer = new DataOutputStream(clien
40、tSocket.getOutputStream();,Create input stream,Create client socket, connect to server,Create output stream attached to socket,2: Application Layer,45,Example: Java client (TCP), cont.,BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream(); sentence = in
41、FromUser.readLine(); outToServer.writeBytes(sentence + n); modifiedSentence = inFromServer.readLine(); System.out.println(FROM SERVER: + modifiedSentence); clientSocket.close(); ,Create input stream attached to socket,Send line to server,Read line from server,2: Application Layer,46,Example: Java se
42、rver (TCP),import java.io.*; import .*; class TCPServer public static void main(String argv) throws Exception String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromCli
43、ent = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream();,Create welcoming socket at port 6789,Wait, on welcoming socket for contact by client,Create input stream, attached to socket,2: Application Layer,47,Example: Java server (TCP), cont,DataOutputStream outToClient = new D
44、ataOutputStream(connectionSocket.getOutputStream(); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + n; outToClient.writeBytes(capitalizedSentence); ,Read in line from socket,Create output stream, attached to socket,Write out line to socket,End of while
45、loop, loop back and wait for another client connection,2: Application Layer,48,Socket programming with UDP,UDP: no “connection” between client and server no handshaking sender explicitly attaches IP address and port of destination server must extract IP address, port of sender from received datagram
46、 UDP: transmitted data may be received out of order, or lost,2: Application Layer,49,Client/server socket interaction: UDP,Server (running on hostid),2: Application Layer,50,Example: Java client (UDP),import java.io.*; import .*; class UDPClient public static void main(String args) throws Exception
47、BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName(hostname); byte sendData = new byte1024; byte receiveData = new byte1024; String sentence = inFromUser.readLine(); sendDa
48、ta = sentence.getBytes();,Create input stream,Create client socket,Translate hostname to IP address using DNS,2: Application Layer,51,Example: Java client (UDP), cont.,DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramP
49、acket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData(); System.out.println(FROM SERVER: + modifiedSentence); clientSocket.close(); ,Create datagram with data-to-send, length, IP addr
50、, port,Send datagram to server,Read datagram from server,2: Application Layer,52,Example: Java server (UDP),import java.io.*; import .*; class UDPServer public static void main(String args) throws Exception DatagramSocket serverSocket = new DatagramSocket(9876); byte receiveData = new byte1024; byte s
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 冷凍藥品倉(cāng)儲(chǔ)服務(wù)合同
- 無(wú)紡布及其制品項(xiàng)目融資渠道探索
- 食品餐飲行業(yè)食品安全及質(zhì)量免責(zé)合同
- 專項(xiàng)借款合同
- 兒童醫(yī)院耗材采購(gòu)合同
- 多方股東合伙合同范本
- 能源科技領(lǐng)域?qū)@夹g(shù)轉(zhuǎn)讓合同
- 合同詐騙罪的報(bào)案材料案例分享
- 移動(dòng)應(yīng)用程序定制開(kāi)發(fā)合同
- 智能科技產(chǎn)品授權(quán)合同
- 江蘇省蘇州市2024-2025學(xué)年高三上學(xué)期1月期末生物試題(有答案)
- 銷(xiāo)售與銷(xiāo)售目標(biāo)管理制度
- 2025年第一次工地開(kāi)工會(huì)議主要議程開(kāi)工大吉模板
- 第16課抗日戰(zhàn)爭(zhēng)課件-人教版高中歷史必修一
- 對(duì)口升學(xué)語(yǔ)文模擬試卷(9)-江西省(解析版)
- 糖尿病高滲昏迷指南
- 壁壘加筑未來(lái)可期:2024年短保面包行業(yè)白皮書(shū)
- 2024年四川省廣元市中考物理試題(含解析)
- 環(huán)保局社會(huì)管理創(chuàng)新方案市環(huán)保局督察環(huán)保工作方案
- 2024至2030年中國(guó)水質(zhì)監(jiān)測(cè)系統(tǒng)行業(yè)市場(chǎng)調(diào)查分析及產(chǎn)業(yè)前景規(guī)劃報(bào)告
- 運(yùn)動(dòng)技能學(xué)習(xí)
評(píng)論
0/150
提交評(píng)論