1. Trang chủ
  2. » Giáo án - Bài giảng

mạng máy tính nâng cao nguyễn đức thái chương 2 application sinhvienzone com

115 42 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 115
Dung lượng 2,45 MB

Nội dung

Zo ne C om Chapter Application Layer nh Vi en A note on the use of these ppt slides: Si We’re making these slides freely available to all (faculty, students, readers) They’re in PowerPoint form so you can add, modify, and delete slides (including this one) and slide content to suit your needs They obviously represent a lot of work on our part In return for use, we only ask the following:  If you use these slides (e.g., in a class) in substantially unaltered form, that you mention their source (after all, we’d like people to use our book!)  If you post any slides in substantially unaltered form on a www site, that you note that they are adapted from (or perhaps identical to) our slides, and note our copyright of this material Computer Networking: A Top Down Approach, 4th edition Jim Kurose, Keith Ross Addison-Wesley, July 2007 Thanks and enjoy! JFK/KWR All material copyright 1996-2007 J.F Kurose and K.W Ross, All Rights Reserved SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn om Chapter 2: Application layer  2.1 Principles of  C  2.7 Socket programming ne with TCP  2.8 Socket programming with UDP Zo nh Vi en network applications  2.2 Web and HTTP  2.3 FTP  2.4 Electronic Mail  2.6 P2P applications SMTP, POP3, IMAP Si  2.5 DNS SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn Chapter 2: Application Layer om  learn about protocols Zo ne C by examining popular application-level protocols Si nh Vi en Our goals:  conceptual, implementation aspects of network application protocols  transport-layer service models  client-server paradigm  peer-to-peer paradigm SinhVienZone.com     HTTP FTP SMTP / POP3 / IMAP DNS  programming network applications  socket API 2: Application Layer https://fb.com/sinhvienzonevn om Some network apps  voice over IP  web  real-time video C  e-mail nh Vi en  P2P file sharing Zo  remote login  multi-user network conferencing  grid computing ne  instant messaging   Si games  streaming stored video clips  SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn Creating a network app No need to write software for network-core devices application transport network data link physical Network-core devices not run user applications applications on end systems allows for rapid app development, propagation Si  C communicate over network e.g., web server software communicates with browser software ne  systems Zo  run on (different) end nh Vi en  om write programs that application transport network data link physical  SinhVienZone.com application transport network data link physical 2: Application Layer https://fb.com/sinhvienzonevn om Chapter 2: Application layer  2.1 Principles of  SMTP, POP3, IMAP C Zo ne with TCP  2.8 Socket programming with UDP  2.9 Building a Web server Si  2.5 DNS  2.7 Socket programming nh Vi en network applications  2.2 Web and HTTP  2.3 FTP  2.4 Electronic Mail  2.6 P2P applications SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn om Application architectures ne  Peer-to-peer (P2P) C  Client-server Si nh Vi en Zo  Hybrid of client-server and P2P SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn Client-server architecture Si client/server nh Vi en Zo ne C om server:  always-on host  permanent IP address  server farms for scaling clients:     SinhVienZone.com communicate with server may be intermittently connected may have dynamic IP addresses not communicate directly with each other 2: Application Layer https://fb.com/sinhvienzonevn  om Pure P2P architecture no always-on server C  arbitrary end systems nh Vi en Zo ne directly communicate peer-peer  peers are intermittently connected and change IP addresses Si Highly scalable but difficult to manage SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn Hybrid of client-server and P2P Si nh Vi en Zo ne C om Skype  voice-over-IP P2P application  centralized server: finding address of remote party:  client-client connection: direct (not through server) Instant messaging  chatting between two users is P2P  centralized service: client presence detection/location • user registers its IP address with central server when it comes online • user contacts central server to find IP addresses of buddies SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn 10 Socket programming with TCP C ne Si nh Vi en Zo 1) client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket (inFromServer stream) om Example client-server app: SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn 101 om Example: Java client (TCP) ne C import java.io.*; import java.net.*; class TCPClient { nh Vi en Zo public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; Create input stream Socket clientSocket = new Socket("hostname", 6789); Si Create client socket, connect to server BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Create output stream attached to socket SinhVienZone.com DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); 2: Application Layer https://fb.com/sinhvienzonevn 102 om Example: Java client (TCP), cont Create input stream attached to socket Zo ne C BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); Send line to server Read line from server nh Vi en sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); Si System.out.println("FROM SERVER: " + modifiedSentence); clientSocket.close(); } } SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn 103 Example: Java server (TCP) om import java.io.*; import java.net.*; ne C class TCPServer { Zo ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Si Wait, on welcoming socket for contact by client nh Vi en Create welcoming socket at port 6789 public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence; Create input stream, attached to socket SinhVienZone.com Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); 2: Application Layer https://fb.com/sinhvienzonevn 104 om Example: Java server (TCP), cont C Create output stream, attached to socket ne DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); Read in line from socket nh Vi en Zo clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; Write out line to socket outToClient.writeBytes(capitalizedSentence); } } Si } SinhVienZone.com End of while loop, loop back and wait for another client connection 2: Application Layer https://fb.com/sinhvienzonevn 105 om Chapter 2: Application layer  2.1 Principles of  C  2.7 Socket programming ne with TCP  2.8 Socket programming with UDP Zo nh Vi en network applications  2.2 Web and HTTP  2.3 FTP  2.4 Electronic Mail  2.6 P2P applications SMTP, POP3, IMAP Si  2.5 DNS SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn 106 .C ne application viewpoint nh Vi en Zo UDP: no “connection” between client and server  no handshaking  sender explicitly attaches IP address and port of destination to each packet  server must extract IP address, port of sender from received packet om Socket programming with UDP UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server Si UDP: transmitted data may be received out of order, or lost SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn 107 Client/server socket interaction: UDP Server (running on hostid) om C ne Zo nh Vi en create socket, port= x serverSocket = DatagramSocket() Client read datagram from serverSocket Si write reply to serverSocket specifying client address, port number SinhVienZone.com create socket, clientSocket = DatagramSocket() Create datagram with server IP and port=x; send datagram via clientSocket read datagram from clientSocket close clientSocket 2: Application Layer https://fb.com/sinhvienzonevn 108 Example: Java client (UDP) Si UDP p a cke t client UDP socket packet (recall thatTCP received “byte stream”) UDP p a cke t c lie n tS o c k e t to n e tw o rk SinhVienZone.com re c e iv e P a c k e t packet (recall that TCP sent “byte stream”) om ne nh Vi en Output: sends Input: receives Zo P ro c e s s sendPacket Client process m o n ito r C in p u t s tre a m in F r o m U s e r k e y b o a rd UDP so cke t fro m n e tw o rk 2: Application Layer https://fb.com/sinhvienzonevn 109 om Example: Java client (UDP) ne class UDPClient { public static void main(String args[]) throws Exception { Zo Create input stream BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); nh Vi en Create client socket DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName("hostname"); Si Translate hostname to IP address using DNS C import java.io.*; import java.net.*; byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn 110 ne Send datagram to server DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); C Create datagram with data-to-send, length, IP addr, port om Example: Java client (UDP), cont Zo clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); nh Vi en Read datagram from server clientSocket.receive(receivePacket); Si String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } } SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn 111 om Example: Java server (UDP) C import java.io.*; import java.net.*; ne Zo DatagramSocket serverSocket = new DatagramSocket(9876); nh Vi en Create datagram socket at port 9876 class UDPServer { public static void main(String args[]) throws Exception { byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; Si while(true) { Create space for received datagram Receive datagram SinhVienZone.com DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); 2: Application Layer https://fb.com/sinhvienzonevn 112 om Example: Java server (UDP), cont String sentence = new String(receivePacket.getData()); Get IP addr port #, of sender C InetAddress IPAddress = receivePacket.getAddress(); ne int port = receivePacket.getPort(); Zo String capitalizedSentence = sentence.toUpperCase(); nh Vi en sendData = capitalizedSentence.getBytes(); Create datagram to send to client serverSocket.send(sendPacket); Si Write out datagram to socket DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); } } } SinhVienZone.com End of while loop, loop back and wait for another datagram 2: Application Layer https://fb.com/sinhvienzonevn 113 Chapter 2: Summary C  specific protocols:  HTTP  FTP  SMTP, POP, IMAP  DNS  P2P: BitTorrent, Skype  application service  nh Vi en requirements: Zo ne  application architectures  client-server  P2P  hybrid om our study of network apps now complete! reliability, bandwidth, delay  socket programming Si  Internet transport service model   connection-oriented, reliable: TCP unreliable, datagrams: UDP SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn 114 Chapter 2: Summary C om Most importantly: learned about protocols  typical request/reply message exchange:   control vs data msgs Zo client requests info or service server responds with data, status code nh Vi en  ne Important themes: Si  message formats:  headers: fields giving info about data  data: info being communicated SinhVienZone.com     in-band, out-of-band centralized vs decentralized stateless vs stateful reliable vs unreliable msg transfer “complexity at network edge”  2: Application Layer https://fb.com/sinhvienzonevn 115 ... SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn 19 om Chapter 2: Application layer  2. 1 Principles of  2. 6 P2P applications network applications  2. 2 Web and HTTP C Si  2. 5 DNS... Chapter 2: Application layer  2. 1 Principles of  C  2. 7 Socket programming ne with TCP  2. 8 Socket programming with UDP Zo nh Vi en network applications  2. 2 Web and HTTP  2. 3 FTP  2. 4 Electronic... and HTTP  2. 3 FTP  2. 4 Electronic Mail  2. 6 P2P applications SinhVienZone.com 2: Application Layer https://fb.com/sinhvienzonevn om Application architectures ne  Peer-to-peer (P2P) C  Client-server

Ngày đăng: 30/01/2020, 23:01