DN04 应用层2.ppt_第1页
DN04 应用层2.ppt_第2页
DN04 应用层2.ppt_第3页
DN04 应用层2.ppt_第4页
DN04 应用层2.ppt_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 implemented in hier

2、archy 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”,DNS name servers,no server has all name-to-IP address mapp

3、ings 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 not centralize DNS? single point of failure

4、 traffic volume distant centralized database maintenance doesnt scale!,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 mapping returns mapping to local name server dozen root name serv

5、ers worldwide,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 server contacts authoritative name server, , if necessary,requesting ho

6、st surf.eurecom.fr,,root name server,authorititive name server ,1,2,3,4,5,6,DNS example,Root name server: may not know authoratiative name server may know intermediate name server: who to contact to find authoritative name server,requesting host surf.eurecom.fr,herm

7、,root name server,1,2,3,4,5,6,authoritative name server ,7,8,DNS: iterated queries,recursive query(递归查询): puts burden of name resolution on contacted name server heavy load? iterated query(迭代查询): contacted server replies with name of server to contact “I dont know t

8、his 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,a. 以机构区分为最高域名,常见有: com (商用机构) gov(政府机构) edu (教育机构) net (网络机构) mil (军事机构) 等 如: (雅虎中文网站),b. 以地址区分为最高域名,如: cn(中国) tw(中国台湾) hk(

9、香港) us(美国) uk(英国) jp(日本) sg(新加坡),如: (人民日报网站) .sg (新加坡联合早报网站),其中顶级域名分为两类,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

10、/dnsind-charter.html,DNS records,DNS: distributed 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 “canonical” (the real) name value i

11、s canonical name,Type=MX value is hostname of mailserver associated with name,DNS protocol, messages,DNS protocol : query and reply messages, both with same message format,msg header identification: 16 bit # for query, reply to query uses same # flags: query or reply recursion desired recursion avai

12、lable reply is authoritative,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,Socket programming,Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/serve

13、r paradigm two types of transport service via socket API: unreliable datagram reliable, byte stream-oriented,Goal: learn how to build client/server applications that communicate using sockets,Socket-programming using TCP,Socket: a door between application process and end-end-transport protocol (UDP

14、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 application developer,controlled by operating system,host or server,internet,Socket programming with TCP,Client must contact ser

15、ver server process must first be running server must have created socket (door) that welcomes clients contact Client contacts server by: creating client-local TCP socket specifying IP address, port number of server process,When client creates socket: client TCP establishes connection to server TCP W

16、hen contacted by client, server TCP creates new socket for server process to communicate with client allows server to talk with multiple clients,Socket programming with TCP,Example client-server app: client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer

17、stream) server reads line from socket server converts line to uppercase, sends back to client client reads, prints modified line from socket (inFromServer stream),Input stream: sequence of bytes into process Output stream: sequence of bytes out of process,client socket,inFromUser,outToServer,iinFrom

18、Server,Client/server socket interaction: TCP,Server (running on hostid),Client,Example: Java client (TCP),import java.io.*; import .*; class TCPClient public static void main(String argv) throws Exception String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new In

19、putStreamReader(System.in); Socket clientSocket = new Socket(hostname, 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream();,Create input stream,Create client socket, connect to server,Create output stream attached to socket,Example: Java client (TCP), cont.,Buff

20、eredReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream(); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + n); modifiedSentence = inFromServer.readLine(); System.out.println(FROM SERVER: + modifiedSentence); clientSocket.close(); ,Create inp

21、ut stream attached to socket,Send line to server,Read line from server,Example: Java server (TCP),import java.io.*; import .*; class TCPServer public static void main(String argv) throws Exception String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789);

22、 while(true) Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = 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,Exampl

23、e: Java server (TCP), cont,DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream(); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + n; outToClient.writeBytes(capitalizedSentence); ,Read in line from socket,Create output st

24、ream, attached to socket,Write out line to socket,End of while loop, loop back and wait for another client connection,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

25、, port of sender from received datagram UDP: transmitted data may be received out of order, or lost,Client/server socket interaction: UDP,Server (running on hostid),Example: Java client (UDP),import java.io.*; import .*; class UDPClient public static void main(String args) throws Exception BufferedR

26、eader 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(); sendData = sent

27、ence.getBytes();,Create input stream,Create client socket,Translate hostname to IP address using DNS,Example: Java client (UDP), cont.,DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new Datagra

28、mPacket(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, port,Send datagram to server,Re

29、ad datagram from server,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 sendData = new byte1024; while(true) DatagramPacket rece

30、ivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket);,Create datagram socket at port 9876,Create space for received datagram,Receive datagram,Example: Java server (UDP), cont,String sentence = new String(receivePacket.getData(); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddre

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论