Presentation is loading. Please wait.

Presentation is loading. Please wait.

Departamento de Tecnología Electrónica

Similar presentations


Presentation on theme: "Departamento de Tecnología Electrónica"— Presentation transcript:

1 Departamento de Tecnología Electrónica
Computer Networking Some of these slides are given as copyrighted material from: Computer Networking: A Top Down Approach , 5th edition. Jim Kurose, Keith Ross Addison-Wesley, April Chapter 2 The Application layer

2 Chapter 2: The Application Layer
Our goals: conceptual, implementation aspects of network application protocols transport-layer service models client-server paradigm peer-to-peer paradigm learn about protocols by examining popular application-layer protocols HTTP DNS programming network applications socket API Application 2-2

3 Some network apps e-mail web instant messaging remote login
P2P file sharing multi-user network games streaming stored video (e.g. YouTube) voice over IP (VoIP) real-time video conferencing cloud computing Application 2-3

4 Creating a network app write programs that
application transport network data link physical write programs that run on (different) end systems communicate over network e.g., web server software communicates with browser software No need to write software for network-core devices network-core devices do not run user applications applications on end systems allows for rapid app development, propagation application transport network data link physical application transport network data link physical Application 2-4

5 Chapter 2: Application layer
2.1 Principles of network applications 2.2 DNS 2.3 Web and HTTP 2.4 Socket programming with TCP 2.5 Socket programming with UDP Application 2-5

6 Application architectures
client-server peer-to-peer (P2P) hybrid of client-server and P2P Note: IP address: it uniquely identifies the devices (end systems, routers, etc...) connected to a TCP/IP network. The ISP assigns a static (fixed) or dynamic (variable) IP addr. More soon ... Application 2-6

7 Client-server architecture
always-on host permanent IP address server farms for scaling clients: communicate with server may be intermittently connected may have dynamic IP addresses do not communicate directly with each other client/server Application 2-7

8 Pure P2P architecture no always-on server
arbitrary end systems directly communicate peers are intermittently connected and change IP addresses highly scalable but difficult to manage peer-peer Application 2-8

9 Hybrid of client-server and P2P
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 Application 2-9

10 How is app layer implemented?
Web browsers, e.g.: Mozilla firefox, Chrome, Internet Explore, Safari,… User interface User interface Application Protocol Application Application A_PDU SAP SAP Transport Transport Internet Application 2-10 10

11 App-layer protocol defines
types of exchanged messages, e.g., request, response message syntax: what fields are in messages & how fields are distinguished message semantics meaning of information in fields rules for when and how processes send & respond to messages public-domain protocols: defined in RFCs allows for interoperability e.g., HTTP, SMTP proprietary protocols: e.g., Skype Application 2-11

12 Process communication
client process: process that initiates communication server process: process that waits to be contacted process: program running within a host. within the same host, communication is held using inter-process communication (defined by OS). In different hosts, communication is done by exchanging messages (PDUs). Communication services (generally defined by OS) are used. Note: applications with P2P architectures have both client processes & server processes Application 2-12

13 Sockets (SAP) process sends/receives messages to/from its socket
socket analogous to door sending process sends message out door sending process relies on transport infrastructure on the other side of the door, bringing message to socket at receiving process process TCP with buffers, variables socket client process TCP with buffers, variables socket server controlled by app developer Internet controlled by OS API: (1) choice of transport protocol; (2) ability to fix a few parameters (more on this later) Application 2-13

14 How is a socket identified?
If you want to send a friend a mail you need to know his address to reach his home mailbox Each end system has unique 32-bit IP address (IPv4) Q: Is your friend’s address enough to make the letters reach him? A: No. Several people may be living at the same home. Several app protocols can be running on one end system Web browser, client, Skype… For every IP address you have an associated name (hostname) which are used to identify the network devices by humans and applications. For example, = More on Names and IPs on next section… Note Application 2-14

15 How is a socket identified?
Each app protocol is identified by a port number Client port number and server port number may not be the same example port numbers: HTTP server: 80 DNS server: 53 Mail server: 25 ICANN (Internet Corporation for Assigned Names and Numbers) is responsible for public app protocols port registering Socket is identified by the pair: IP address Port number Application 2-15

16 Example DTE web server Internet Aplicación Aplicación Transport
Interfaz Usuario Interfaz Usuario Aplicación Aplicación , 80 Client IP address, port Transport Transport Internet Application 2-16 16

17 OS Internet Communication Service
Localhost: Connecting 2 process on the same host localhost: is a “reserved name” related to a particular IP address which always identify our own end system. It’s useful to connect network applications on a single host (without any other physical network connection). In general, it allows interprocess comunications in the end system using the same Internet protocol stack. Note Localhost is usually asociated to IP address , but other IPs may be used…. More on Chapter 4… OS Internet Communication Service socket1 process1 socket2 process2 Q: How can the communication service on the host able to distinguish each process? Application 2-17 17 17

18 What transport service does an app need?
Data loss some apps (e.g., audio) can tolerate some loss other apps (e.g., file transfer, telnet) require 100% reliable data transfer Throughput some apps (e.g., multimedia) require minimum amount of throughput to be “effective” other apps (“elastic apps”) make use of whatever throughput they get Security encryption, data integrity, … Timing some apps (e.g., Internet telephony, interactive games) require low delay to be “effective” Application 2-18

19 Transport service requirements of common apps
Application file transfer Web documents real-time audio/video stored audio/video interactive games instant messaging Data loss no loss loss-tolerant Throughput elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up Time Sensitive no yes, 100’s msec yes, few secs yes and no Application 2-19

20 Internet transport protocols services
TCP service: connection-oriented: setup required between client and server processes reliable transport between sending and receiving process flow control: sender won’t overwhelm receiver congestion control: throttle sender when network overloaded does not provide: timing, minimum throughput guarantees, security UDP service: unreliable data transfer between sending and receiving process does not provide: connection setup, reliability, flow control, congestion control, timing, throughput guarantee, or security Q: Why UDP? Application 2-20

21 Internet apps: application, transport protocols
layer protocol SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] HTTP (e.g., YouTube), RTP [RFC 1889] SIP, RTP, propietary (e.g., Skype) Underlying transport protocol TCP TCP or UDP typically UDP Application remote terminal access Web file transfer streaming multimedia Internet telephony Application 2-21

22 Chapter 2: Application layer
2.1 Principles of network applications 2.2 DNS 2.3 Web and HTTP 2.4 Socket programming with TCP 2.5 Socket programming with UDP Application 2-22

23 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 address and name, and viceversa? Domain Name System: distributed database 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 Application 2-23

24 HTTP client HTTP server Internet DNS server DNS client
DNS server DNS client DNS adds an additional delay Internet HTTP server Application 2-24

25 DNS DNS services Why not centralize DNS?
hostname to IP address translation (direct) IP address to hostname translation (inverse) host aliasing Canonical, alias names mail server aliasing @domain load distribution replicated Web servers: set of IP addresses for one canonical name Why not centralize DNS? single point of failure traffic volume distant centralized database maintenance … doesn’t scale! Which transport service does it use? Not reliable UDP, port 53 Application 2-25

26 DNS: caching and updating records
once (any) name server learns mapping, it caches mapping cache entries timeout (disappear) after some time TLD servers typically cached in local name servers Thus root name servers not often visited update/notify mechanisms among DNS servers proposed IETF standard RFC 2136 Application 2-26

27 DNS: how does it work? (simplified!)
If an application have a hostname and not the associated IP address it requests the resolution to the DNS service in the same host (reverse resolution is also available). El DNS service check if there’s an entry in the DNS cache for the hostname or IP address and then… … if there’s an entry in the cache: It returns the requested resolution to the application. … if there’s no entry in the cache: The DNS service sends a DNS REQUEST (DNS_PDU) to the DNS Server IP address configured on the host (at least one is usually configured) and wait for the DNS REPLY (another type of DNS_PDU) from the DNS Server it was requested. The reply is then added to the cache to accelerate future requests and it’s also returned to the application. If it’s not possible to resolve the hostname or IP address, it notifies the application. Note When a DNS Server receives a DNS REQUEST, its behaviour is the same as a host, it first tries its own cache and if it’s not available it generates a Request to another DNS Server in a higher hierarchy, and the Reply is then forwarded back to the client. Application 2-27 27 27

28 Chapter 2: Application layer
2.1 Principles of network applications 2.2 DNS 2.3 Web and HTTP 2.4 Socket programming with TCP 2.5 Socket programming with UDP Application 2-28

29 Web and HTTP First, a review… web page consists of objects
object can be HTML file, JPEG image, Java applet, audio file,… web page consists of base HTML-file which includes several referenced objects each object is addressable by a URL (Uniform Resource Locator) example URL: host name path name Application 2-29

30 HTML language format Aside
It allows formatting web pages; created in It includes elements with TAGS in <>. Each element usually have 4 fields: a starting tag (like “<html>”) & an ending tag (like “</html>”), some attributes (in starting tag) and some contents (between the tags). <!DOCTYPE html…> remarks document start (optional) <html>document</html> start/finish of document <head>headers</head> header content (not visible to the end user, like title, styles, metainformation, etc…) <body>webpage</body> it contains the body of the webpage, with: from <h1> to <h6> headings <table>table</table> creates a table with fils/cols <a href=“URL”>link</a> hiperlink: when the user clicks on the link, the URL object is requested. <img src=“URL”> object reference, navigator requests the URL object inmediately to be shown. You can view the HTML code in any webpage with your favourite navigator, right-click -> view source code. Aside Application 2-30 30 30

31 HTTP overview HTTP: hypertext transfer protocol
Web’s application layer protocol client/server model client: browser that requests, receives, “displays” Web objects server: Web server sends objects in response to requests HTTP request PC running IExplorer HTTP response HTTP request Server running Apache Web server HTTP response Linux running Firefox Application 2-31

32 HTTP overview (continued)
Uses TCP: client initiates TCP connection (creates socket) to server, port 80 in server server accepts TCP connection from client HTTP messages (A_PDU’s: Application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server) TCP connection closed HTTP is “stateless” server maintains no information about past client requests note protocols that maintain “state” are complex! past history (state) must be maintained if server/client crashes, their views of “state” may be inconsistent, must be synchronized Application 2-32

33 HTTP connections non-persistent HTTP
one object sent over TCP connection. persistent HTTP multiple objects can be sent over single TCP connection between client, server. Application 2-33

34 (contains text & references to 13 objects)
Non-persistent HTTP (contains text & references to 13 objects) suppose user enters URL: 1a. HTTP client initiates TCP connection to HTTP server (process) at on port 80 1b. HTTP server at host waiting for TCP connection at port 80. “accepts” connection, notifying client 2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object with pathname /personal/smartin/lab3/r eferencias.html 3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket time Application 2-34

35 Nonpersistent HTTP (cont.)
4. HTTP server closes TCP connection. 5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 13 referenced objects (images, scripts, …) time 6. Steps 1-5 repeated for each of 13 objects with different unique URLs Application 2-35

36 Non-Persistent HTTP: Response time
RTT (Round-Trip Time): time for a PDU with a few bytes to travel from client to server and back. Response time: one RTT to initiate TCP connection one RTT for HTTP request and first few bytes of HTTP response to return file transmission time total = 2RTT+transmit time time to transmit file initiate TCP connection RTT request received time Application 2-36

37 Persistent HTTP non-persistent HTTP issues: persistent HTTP
requires 2 RTTs per object OS overhead for each TCP connection persistent HTTP server leaves connection open after sending response subsequent HTTP messages between same client/server sent over open connection client sends requests as soon as it finds a referenced object Each referenced object takes only 1 RTT Parallel HTTP connections: browsers often open parallel TCP connections to fetch referenced objects faster. They are requested sequentally per each connection (persistent or not). Note that: Application 2-37

38 Mensajes HTTP (HTTP_PDU)
2 types of messages: HTTP Request: Sent by the client Takes neccessary information Transporta información (HTTP_PCI) to get an object from the server (HTTP_UD) ASCII chracters (intelligible text) HTTP Response: Sent by the server Takes the object (HTTP_UD) requested by the client and some control information (HTTP_PCI) Aplicación 2-38

39 HTTP request message Note: UD request line (GET, POST, HEAD commands)
<CR>: Carriage-Return : \r <LF>: Line-Feed: \n UD request line (GET, POST, HEAD commands) GET /index.html HTTP/1.1\r\n Host: www-net.cs.umass.edu\r\n User-Agent: Firefox/3.6.10\r\n Accept: text/html,application/xhtml+xml\r\n Accept-Language: en-us,en;q=0.5\r\n Accept-Encoding: gzip,deflate\r\n Accept-Charset: ISO ,utf-8;q=0.7\r\n Keep-Alive: 115\r\n Connection: keep-alive\r\n \r\n header lines \r & \n at start of line indicates end of header lines Application 2-39

40 Some HTTP headers CLIENT can send
Host: hostname (name of the web site) User-Agent: web_navigator_version Accept-xxx: preferences_list_for_xxx_feature Connection: keep-alive Client if asking the server to stablish persistant connection Keep-Alive: nnn Client if asking the server to keep the persistant connection alive for nnn seconds. Aplicación 2-40 40 40

41 HTTP request message: general format
line header lines PCI PDU body UD Application 2-41

42 Uploading form input Web page often includes form input (with some parameters that are sended to server). There are two methods to send: POST method: input is uploaded to server in entity body GET method: Inputs are uploaded in URL field of request line (separated by “?” and “&”): GET /animalsearch?monkeys&banana HTTP/1.1\r\n Host: Application 2-42

43 Method types HTTP/1.0 (RFC-1945) GET POST HEAD HTTP/1.1 (RFC-2616)
Identical to GET but object is not included in response (only corresponding headers) HTTP/1.1 (RFC-2616) GET, POST, HEAD PUT uploads file in entity body to path specified in URL field DELETE deletes file specified in the URL field Application 2-43

44 HTTP response message status line (protocol status code status phrase)
HTTP/ OK\r\n Date: Sun, 26 Sep :09:20 GMT\r\n Server: Apache/ (CentOS)\r\n Last-Modified: Tue, 30 Oct :00:02 GMT\r\n ETag: "17dc6-a5c-bf716880"\r\n Accept-Ranges: bytes\r\n Content-Length: 2652\r\n Keep-Alive: timeout=10, max=100\r\n Connection: Keep-Alive\r\n Content-Type: text/html; charset=ISO \r\n \r\n data data data data data ... header lines data, e.g., requested HTML file Application 2-44

45 Some HTTP headers the SERVER can send
Date: date Last-Modified: (last modification of the requested object) Server: web_server_version Content-Type: object_type (HTML, image, text …) Content-Length: body_length (in bytes) Connection: keep-alive Server announces the connection will be persistant. Keep-Alive: timeout=ttt, max=nnn Server will close the connection after ttt seconds of inactivity or otherwise after nnn seconds. Application 2-45 45 45

46 HTTP response status codes
status code appears in 1st line in serverclient response message. some sample codes: 200 OK request succeeded, requested object later in this msg 301 Moved Permanently requested object moved, new location specified later in this msg (Location:) 400 Bad Request request msg not understood by server 404 Not Found requested document not found on this server 505 HTTP Version Not Supported Application 2-46

47 Trying out HTTP (client side) for yourself
1. Telnet to your favourite Web server: telnet 80 opens TCP connection to port 80 (default HTTP server port) at anything typed in sent to port 80 at 2. type in a GET HTTP request: by typing this, you send this minimal (but complete) GET request to HTTP server GET /docencia/ HTTP/1.1 Host: 3. look at response message sent by HTTP server! (or use Wireshark!) Q: What happens if you send “hello”? Application 2-47

48 User-server state: cookies
example: Susan always accesses Internet from her PC visits specific e-commerce site for first time (e.g. Amazon) when initial HTTP requests arrives at site, site creates: unique ID entry in back-end database for ID many Web sites use cookies four components: 1) cookie header line of HTTP response message 2) cookie header line in HTTP request message 3) cookie file kept on user’s host, managed by user’s browser 4) back-end database at Web site Application 2-48

49 Cookies: Example Client visits AMAZON AMAZON server Amazon server
ebay 8734 usual http request msg Amazon server creates ID 1678 for user create entry cookie file usual http response Set-cookie:1678 ebay 8734 amazon 1678 usual http request msg cookie:1678 cookie- specific action access usual http request msg cookie:1678 cookie- specific action access usual http response msg backend database one week later: ebay 8734 amazon 1678 usual http response msg Application 2-49

50 Cookies (continued) cookies and privacy: what cookies can bring:
Note cookies and privacy: cookies allow sites to learn a lot about you you may supply personal information to sites (name, ,…) what cookies can bring: authorization shopping carts recommendations user session state (Web e- mail) Application 2-50

51 Web caches (proxy server)
Goal: satisfy client request without involving origin server user sets browser: Web accesses via cache-proxy browser sends all HTTP requests to cache-proxy object in cache: cache returns object Else, cache requests object from origin server, then returns object to client origin server HTTP request HTTP request client HTTP response HTTP response HTTP request Proxy server HTTP response client origin server Application 2-51

52 More about Web caching - Proxy
cache acts as both client (of the original server) and server (of the user client) typically cache is installed by ISP (university, company, residential ISP) why Web caching? reduce response time for client request reduce traffic on an institution’s access link. enables “poor” content providers to effectively deliver content (but so does P2P file sharing) Application 2-52

53 Conditional GET Goal: don’t send object if cache has up-to-date cached version Cache-proxy: specify date of cached copy in HTTP request If-modified-since: <date> server: response contains no object if cached copy is up-to-date: HTTP/ Not Modified Or modified object is sended with the last- modified date: Last-modified:<date> cache-proxy server HTTP request msg If-modified-since: <date> object modified before <date> HTTP response HTTP/1.0 304 Not Modified HTTP request msg If-modified-since: <date> object modified after <date> HTTP response HTTP/ OK Last-modified: <date> <data> Application 2-53

54 Chapter 2: Application layer
2.1 Principles of network applications 2.2 DNS 2.3 Web and HTTP 2.4 Socket programming with TCP 2.5 Socket programming with UDP Application 2-54

55 Socket programming Goal: learn how to build client/server application that communicate using sockets Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm two types of transport service via socket API: unreliable datagram reliable, byte stream- oriented socket A local-host, application-created, OS-controlled interface (a “door”) where application processes can both send and receive messages to/from another application processes Application 2-55

56 Application protocol Server Client Internet Application Application
User interface User interface Application Application Server IP address, port Client IP address, port Transport Transport Internet Application 2-56 56

57 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 application developer process TCP with buffers, variables socket process TCP with buffers, variables socket controlled by operating system controlled by operating system internet client or server client or server Application 2-57

58 Socket programming with TCP
Client must contact server server process must first be running server must open a socket (door) that welcomes client’s contact Client contacts server by: creating client 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 source port numbers used to distinguish clients (more in Chap 3) application viewpoint TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server Application 2-58

59 Server (running on hostid)
Client/server socket interaction: TCP Server (running on hostid) Client create socket, port=x, for incoming request: welcomeSocket = ServerSocket() Wait for primitive: Connection.indication close connectionSocket read reply from clientSocket TCP connection setup create socket, connect to hostid, port=x clientSocket = Socket() Send primitive: Connection.response wait for incoming connection request connectionSocket = welcomeSocket.accept() Send primitive: Connection.request Wait for primitive: Connection.confirm send request using clientSocket read request from connectionSocket write reply to hostid = IP or hostname Application 2-59

60 Java Stream keyboard monitor stream is a sequence of characters that flow into or out of a process. input stream is attached to some input source for the process, e.g., keyboard or socket. output stream is attached to an output source, e.g., monitor or socket. Ex.: we are going to use 3 streams and 1 socket in the client input stream inFromUser Client process output stream input stream outToServer inFromServer client TCP socket To transport layer From transport layer Application 2-60

61 Socket programming with TCP
Example client-server app: 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) Application 2-61

62 Example: Java client (TCP)
import java.io.*; import java.net.*; 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(clientSocket.getOutputStream()); This package defines Socket() and ServerSocket() classes server name, e.g., T_ICI create input stream create clientSocket object of type Socket, connect to server server port # T_ICI create output stream attached to socket Application 2-62

63 Example: Java client (TCP), cont.
BufferedReader 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 input stream attached to socket Send primitive: Data.request PDU send line to server Wait for primitive: Data.indication read line from server close socket (clean up behind yourself!) Application 2-63

64 Example: Java server (TCP)
import java.io.*; import java.net.*; 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 inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); create welcoming socket at port 6789 wait, on welcoming socket accept() method for client contact create, new socket on return create input stream, attached to socket Application 2-64

65 Example: Java server (TCP), cont
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); } create output stream, attached to socket PDU read in line from socket Wait for primitive: Data.indication write out line to socket PDU Send primitive: Data.request end of while loop, loop back and wait for another client connection Application 2-65

66 Chapter 2: Application layer
2.1 Principles of network applications 2.2 DNS 2.3 Web and HTTP 2.4 Socket programming with TCP 2.5 Socket programming with UDP Application 2-66

67 Socket programming with UDP
UDP: no “connection” between client and server no handshaking sender explicitly attaches IP address and port of destination to each message (PDU) that wants to send server must extract IP address, port of sender from received message UDP: transmitted data may be received out of order, or some may be lost application viewpoint: UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server Application 2-67

68 Server (running on hostid)
Client/server socket interaction: UDP Server (running on hostid) create socket, clientSocket = DatagramSocket() Client Create datagram with server IP and port=x; send datagram via clientSocket create socket, port= x. serverSocket = DatagramSocket() Wait primitive: Data.indication read datagram from serverSocket Send primitive: Data.request close clientSocket read datagram from write reply to serverSocket specifying client address, port number hostid = IP or hostname Application 2-68

69 Example: client (UDP datagrams)
keyboard monitor input stream inFromUser Client process Input: receives packet (recall that TCP received “byte stream”) Output: sends packet (recall that TCP sent “byte stream”) UDP packet UDP packet sendPacket receivePacket client UDP socket UDP socket To transport layer From transport layer Application 2-69

70 Example: Java client (UDP)
import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName("hostname"); byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); create input stream create client socket translate hostname to IP address using DNS Application 2-70

71 Example: Java client (UDP) (cont.)
T_ICI create T_IDU with A_PDU, length, IP addr, port A_PDU DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } T_IDU send T_IDU Send primitive: Data.request create new T_IDU receive T_IDU Wait for primitive: Data.indication Application 2-71

72 Example: Java server (UDP)
import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Create UDP socket at port 9876 (known by client) Wait for primitive: Data.indication create new T_IDU receive T_IDU Application 2-72

73 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, IPAddress, port); serverSocket.send(sendPacket); } get sender IP addr and port # from T_ICI create T_IDU with A_PDU to send, length, IP addr and port # Send T_IDU end of while loop, loop back and wait for another datagram Application 2-73

74 PROBLEMs AND EXERCISES
Departamento de Tecnología Electrónica Computer Networking – Chapter 2: Application layer PROBLEMs AND EXERCISES Application 2-74

75 Pr1: True or false? With non-persistent connections between browser and origin server, it is possible for a single TCP segment to carry two different HTTP request messages. A user requests a Web page that consists of some text and two images. For this page, the client sends one request message and receives three response messages. These two different Web pages and can be sent over the same persistent connection. The “Date:” header in the HTTP response message indicates when the object in the response was last modified. HTTP response messages never have an empty message body. Application 2-75 75

76 Pr2: Application-Transport
Consider an HTTP client that wants to retrieve a Web document from a given URL. HTTP server’s IP address is initially unknown. What transport and application-layer protocols besides HTTP are needed in this scenario? Application 2-76 76

77 Pr3: HTTP client headers
Consider the following string of ASCll characters that were captured by Wireshark when the browser sent an HTTP GET message (i .e., this is the actual content of an HTTPGET message). The characters <cr><l/> are carriage return and line-feed characters (that is, the character string <cr> in the text below represents the single carriage-return character that was contained at that point in the HTTP header). Answer the following questions, indicating where in the HTTP GET message below you found the answer.  GET /cs453/index.html HTTP/l.l<cr><lf>Host: gaia.cs.umass.edu<cr><lf>User-Agent: Mozilla/5.0 (WindowsiUi Windows NT 5.1i en-USi rv:1.7.2) Gecko/ Netscape/7.2 (ax) <cr><lf>Accept:ext/xml, application/xml, application/xhtml+xml, text/htmliq=0.9, text/plain iq=0.8,image/png,*/*;q=0.5<cr><lf>Accept-Language: en- us,enjq=0.5<cr><lf>AcceptEncoding:zip,deflate<cr><lf>Accept- Charset: ISO ,utf-8;q=0.7,*jq=0.7<cr><lf>Keep-Alive: 300<cr><If>Connection:keep-alive<cr><lf><cr><lf> What is the URL of the document requested by the browser?  What version of HTTP is the browser running? Does the browser request a non-persistent or a persistent connection? What is the IP address of the host on which the browser is running? What type of browser initiates this message? Why is the browser type needed in an HTTP request message? Application 2-77 77

78 Pr4: HTTP server headers
The text below shows the reply sent from the server in response to the HTTP GET message in the question above. Answer the following questions, pointing out where in the message below you found the answer. HTTP/ OK<cr><lf>Date: Tue, 07 Mar :39:45GMT<cr><lf>Server: Apache/ (Fedora) <cr><lf>Last- Modified: Sat, 10 Dec :27:46 GMT<cr><lf>ETag: "526c3-f22- a88a4c80"<cr><lf>AcceptRanges: bytes<cr><lf>Content-Length: 3874<cr><lf> Keep-Alive: timeout=max=100<cr><lf>Connection: Keep- Alive<cr><lf>Content-Type: text/html; charset= ISO <cr><lf><cr><lf><!doctype html public "// w3c//dtd html 4.0 transitional//en"><lf><html><lf> <head><lf> <meta http- equiv="Content-Type“ content="text/htmlj charset=iso "><lf> <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0j U) Netscape]"><lf> <title>CMPSCI 453 / 591 / NTU-ST550A Spring 2005 homepage</title><lf></head><lf> <much more document text following here (not shown) Was the server able to successfully find the document or not? What time was the document reply provided? When was the document last modified? How many bytes are there in the returned document? What are the first 5 bytes of the returned document? Did the server agree to a persistent connection? Application 2-78 78

79 Pr5: RTT with DNS (I) Suppose you click on a link within your Web browser to obtain a Web page. The IP address for the associated URL is not cached in your local host, so a DNS request is necessary to obtain the IP address. Suppose that RTT for a DNS request is RTTDNS. Besides, suppose that the Web page associated with the link contains exactly one object, consisting of a small amount of HTML text (assume object transmission time = 0). Let RTT0 be the RTT between the local host and the Web server. How long does it take since the client clicks on the link until the client receives the object? Application 2-79 79

80 Pr6: RTT with DNS (II) Referring to Problem Pr5, suppose the HTML file references eight very small objects on the same server. Despite of transmission times, how long does it take to get the web page using: Non-persistent HTTP with no parallel TCP connections? Non-persistent HTTP with the browser configured for 5 parallel connections? Persistent HTTP? Application 2-80 80

81 Institutional network
Pr7: Proxy (I) origin servers This figure shows two networks (institutional and public). The institutional network is a high speed LAN. A router in the institutional network and a router in the Internet are connected by 1.5 Mbps. The origin servers are attached to the Internet but are located all over the globe. Suppose that: The average object size = 100 Kbits The average request rate from institution’s browsers to origin servers = 15 requests/sec HTTP request message are negligibly small Delay from institutional router to any origin server and back to router = 2 sec We can calculate the following: utilization on LAN = 15% utilization on access link = 100% As access link uses is 100%, aL/R ~ 1, queues can grow indefinitely and with them the associated delay. Total delay: increses indefinitely. public Internet 1.5 Mbps access link 10 Mbps LAN Institutional network Application 2-81

82 Institutional network
Pr7: Proxy (II) One possible solution: increase bandwidth of access link to, say, 10 Mbps consequences utilization on LAN ? utilization on access link ? average total delay ? Comments ? public Internet 10 Mbps access link 10 Mbps LAN Institutional network Application 2-82

83 Pr7: Proxy (III) Another possible solution: Origin servers
Install proxy-cache server Success rate of 0.4: 40% requests replied by the proxy inmediately 60% requests forwared to the origin web servers Consequences: utilization on LAN ? utilization on access link ? average total delay ? Comments ? Public Internet 1.5 Mbps Access link Institutional network 10 Mbps LAN Institutional proxy Aplicación 2-83 83 83


Download ppt "Departamento de Tecnología Electrónica"

Similar presentations


Ads by Google