Application Layer. Application Layer 1. By Mikkel Christiansen for NA mm7 Spring 2004

Similar documents
Chapter 2 outline. 2.1 Principles of app layer protocols

Review of Previous Lecture

Lecture 6 Application Layer. Antonio Cianfrani DIET Department Networking Group netlab.uniroma1.it

Web, HTTP and Web Caching

Foundations of Telematics

Application Layer. Applications and application-layer protocols. Goals:

Chapter 2: Application Layer. Chapter 2 Application Layer. Some network apps. Application architectures. Chapter 2: Application layer

Application Layer. Goals: Service models. Conceptual aspects of network application protocols Client server paradigm

CSEN 404 Introduction to Networks. Mervat AbuElkheir Mohamed Abdelrazik. ** Slides are attributed to J. F. Kurose

Chapter 2 Application Layer

CS4/MSc Computer Networking. Lecture 3: The Application Layer

Client/Server Computing & Socket Programming

CMSC 332 Computer Networking Web and FTP

Lecture 7 Application Layer. Antonio Cianfrani DIET Department Networking Group netlab.uniroma1.it

1-1. Switching Networks (Fall 2010) EE 586 Communication and. September Lecture 10

Computer Networks. Wenzhong Li. Nanjing University

Chapter 2 Application Layer

Chapter 2 Application Layer

EECS 3214: Computer Network Protocols and Applications

Computer Networks. 2.Application Layer. László Böszörményi Computer Networks Application Layer - 1

Chapter 2. Application Layer. Chapter 2: Application Layer. Application layer - Overview. Some network apps. Creating a network appication

Application Layer: HTTP

Application Layer. Goals:

Application Layer. Applications and application-layer protocols. Goals:

HyperText Transfer Protocol

Lecture 04: Application Layer (Part 01) Principles and the World Wide Web (HTTP) Dr. Anis Koubaa

Lecture 05: Application Layer (Part 02) Domain Name System. Dr. Anis Koubaa

Communication in Distributed Systems: Sockets Programming. Operating Systems

Chapter 2: outline. 2.6 P2P applications 2.7 socket programming with UDP and TCP

CSCD 330 Network Programming Spring 2018

CSC358 Week 2. Adapted from slides by J.F. Kurose and K. W. Ross. All material copyright J.F Kurose and K.W. Ross, All Rights Reserved

Chapter 2 Application Layer

CSEN 503 Introduction to Communication Networks

Chapter 2 Application Layer. Lecture 5 DNS. Computer Networking: A Top Down Approach. 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012

Networking. Layered Model. DoD Model. Application Layer. ISO/OSI Model

Part 2: Application Layer

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Layered Model. DoD Model. ISO/OSI Model

Chapter 2: outline. 2.1 principles of network applications. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Chapter 2 Application Layer

Application Layer. Pure P2P architecture. Client-server architecture. Processes communicating. Hybrid of client-server and P2P. Creating a network app

Chapter 2 Application Layer

Chapter II: Application Layer

Application Layer. Pure P2P architecture. Client-server architecture. Processes communicating. Hybrid of client-server and P2P. Creating a network app

Introduction to Sockets 9/25/14

Domain Name Service. DNS Overview. October 2009 Computer Networking 1

Chapter 2 Application Layer. Lecture 4: principles of network applications. Computer Networking: A Top Down Approach

Application Layer Protocols

DATA COMMUNICATOIN NETWORKING

Chapter 2: Application layer

Chapter 2: Application layer

Application Layer Chapter 2

Chapter 2: Application Layer last updated 22/09/03

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.

CSC 4900 Computer Networks:

Internet Services & Protocols. Application Layer and its Services

Lecture 7: Application Layer Domain Name System

Application Layer: , DNS

Introduction to Computer Networking. Guy Leduc. Chapter 2 Application Layer. Chapter 2: outline

Review for Internet Introduction

Domain Name System (DNS) 김현철 ( 화 ) 정보통신융합서울대학교컴퓨터공학부

Application layer. Some network apps. Client-server architecture. Hybrid of client-server and P2P. Pure P2P architecture. Creating a network app

Internet applications. 2: Application Layer 1

Applications Layer Protocols. Hui Chen, Ph.D. Dept. of Engineering & Computer Science Virginia State University Petersburg, VA 23806

Introduction to Computer Networking. Guy Leduc. Chapter 2 Application Layer. Chapter 2: outline

CMPE 150/L : Introduction to Computer Networks. Chen Qian Computer Engineering UCSC Baskin Engineering Lecture 4

Computer Networking Introduction

CS 3516: Advanced Computer Networks

Chapter 2 Application Layer

Chapter 2: Application Layer

Chapter 2 part B: outline

CS 3516: Advanced Computer Networks

Chapter II: Application Layer

FTP. Mail. File Transfer Protocol (FTP) FTP commands, responses. Electronic Mail. TDTS06: Computer Networks

Chapter 2 Application Layer

WWW: the http protocol

Chapter 2: outline. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Chapter 2 Application Layer

CC451 Computer Networks

Chapter 2 Application Layer

CS 43: Computer Networks. HTTP September 10, 2018

Application-layer Protocols

Goal and A sample Network App

CMPE 150/L : Introduction to Computer Networks. Chen Qian Computer Engineering UCSC Baskin Engineering Lecture 5

Electronic Mail. Three Components: SMTP SMTP. SMTP mail server. 1. User Agents. 2. Mail Servers. 3. SMTP protocol

Chapter 2 Application Layer

Applications & Application-Layer Protocols: (SMTP) and DNS

Section 2: Application layer

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Chapter 2. Application Layer. 2: Application Layer 1

Chapter P2P file sharing network applications 2.22 Web and HTTP 2.3 FTP DNS

Lecture 7b: HTTP. Feb. 24, Internet and Intranet Protocols and Applications

Chapter 2 Application Layer. 2: Application Layer 1

Computer Networking Introduction

CMSC 322 Computer Networks Applications and End-To- End

CS 43: Computer Networks. 10: Naming and DNS September 24, 2018

Network Applications Principles of Network Applications

Computer Networks 1 (Mạng Máy Tính 1) Lectured by: Dr. Phạm Trần Vũ

55:134/22C:178 Computer Communications Lecture Note Set 2 Summer 2004

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Transcription:

Application Layer By Mikkel Christiansen for NA mm7 Spring 2004 Based on power-point material from J.F Kurose and K.W. Ross website Application Layer 1

Last on NA End-systems PCs workstations, servers PDAs phones, toasters Many different applications local ISP regional ISP Communication links fiber, copper, radio, satellite Routers: forward data company network router server workstation mobile Application Layer 2

Network Taxonomy Telecommunication networks Circuit-switched networks Packet-switched networks FDM TDM Networks with VCs Datagram Networks Application Layer 3

Last on NA Transmission delay A Propagation delay B Queueing delay Processing delay Four sources of delay Nodal delay: Sum of delay from all four sources End-to-end delay: Sum of Nodal delays Application Layer 4

Last on NA H l Protocol stacks Each layer takes data from above Adds header information to create new data unit Passes new data unit to layer below source destination H t H n H t H n H t M M M M application transport network link physical application transport network link physical H l H t H n H t H n H t M M M M message segment datagram frame Application Layer 5

Application Layer Today on NA: Conceptual, implementation aspects of network application protocols transport-layer service models client-server paradigm Application Level Protocols HTTP DNS Network programming socket API Application Layer 6

Applications and application-layer protocols Application Communicating, distributed processes E.g., e-mail, Web, P2P file sharing, instant messaging Running in end systems Exchange messages to implement application application transport network data link physical Application-layer protocols One piece of an app Define messages exchanged by apps and actions taken Example: HTTP Use communication services provided by lower layer protocols (TCP, UDP) application transport network data link physical application transport network data link physical Application Layer 7

App-layer protocol defines Types of messages exchanged E.g. request & response messages Syntax of message types what fields in messages & how fields are delineated Semantics of the fields I.e., meaning of information in fields Rules for when and how processes send & respond to messages Application Layer 8

Client-server paradigm Client: Initiates contact with server ( speaks first ) Typically requests service from server, Web: client implemented in browser; e-mail: in mail reader application transport network data link physical request reply Server: Provides requested service to client E.g., Web server sends requested Web page, mail server delivers e-mail application transport network data link physical Application Layer 9

Processes communicating across network Process sends/receives messages to/from its socket Socket analogous to door Sending process shoves message out door host or server process socket TCP with buffers, variables controlled by app developer Internet host or server process socket TCP with buffers, variables API: Choice of transport protocol Ability to fix a few parameters controlled by OS Application Layer 10

Addressing Processes For a process to receive messages, it must have an identifier IP and Port IP identifies the host A unique 32-bit value Port identifies the process One host can have many processes Example: HTTP server uses port 80 host or server process socket TCP with buffers, variables 2227 6789 Internet host or server process socket TCP with buffers, variables 192.168.194.123 1.2.3.4 Application Layer 11

What transport service does an app need? Data loss Can we tolerate some loss? Timing Do we require low delay? Bandwidth Do we require a minimum amount of bandwidth to be effective? Application Layer 12

Transport service requirements of common apps Application Data loss Bandwidth Time Sensitive file transfer e-mail Web documents real-time audio/video stored audio/video interactive games instant messaging no loss no loss no loss loss-tolerant loss-tolerant loss-tolerant no loss elastic elastic elastic audio: 5kbps-1Mbps video:10kbps-5mbps same as above few kbps up elastic no no no yes, 100 s ms yes, few secs yes, 100 s ms yes and no Elastic applications make use of whatever bandwidth is available Application Layer 13

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 bandwidth guarantees UDP service: Unreliable data transfer between sending and receiving process Application Layer 14

Internet apps: application, transport protocols Application e-mail remote terminal access Web file transfer streaming multimedia Internet telephony Application layer protocol SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] proprietary (e.g. RealNetworks) proprietary (e.g., Dialpad) Underlying transport protocol TCP TCP TCP TCP TCP or UDP typically UDP Application Layer 15

Outline Principles of app layer protocols clients and servers app requirements Web and HTTP DNS Socket programming with TCP Application Layer 16

Web and HTTP Web operates on demand, eg. pull protocol 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 Example URL: www.someschool.edu/somedept/pic.gif host name path name Application Layer 17

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 1.0: RFC 1945 HTTP 1.1: RFC 2068 PC running Exploder Mac running Safari HTTP request HTTP response HTTP request HTTP response Server running Apache Web server Application Layer 18

HTTP overview (continued) Uses TCP Tolerates no loss No time constraints Elastic bandwidth requirements HTTP is stateless Server maintains no information about past client requests Stateless is a often used to simplify protocols in distributed systems HTTP is text-based Cross platform! Main events when retrieving a web page Client initiates TCP connection Server accepts TCP connection from client HTTP messages exchanged between browser (HTTP client) and Web server (HTTP server) (TCP connection closed) Application Layer 19

HTTP connections Optimizations Persistent connections Pipelining Nonpersistent HTTP At most one object is sent over a TCP connection. HTTP/1.0 uses nonpersistent HTTP Persistent HTTP Multiple objects can be sent over single TCP connection between client and server. HTTP/1.1 uses persistent connections in default mode Application Layer 20

Nonpersistent HTTP uppose user enters URL www.someschool.edu/somedepartment/home.index (contains text, references to 10 jpeg images) time 1. HTTP client initiates TCP connection to HTTP server (process) at www.someschool.edu on port 80 3. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object somedepartment/home.index 2. HTTP server at host www.someschool.edu waiting for TCP connection at port 80. accepts connection, notifying client 4. HTTP server receives request message, forms response message containing requested object, and sends message into its socket Application Layer 21

Nonpersistent HTTP (cont.) ime 6. HTTP client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects 7. Steps 1-5 repeated for each of 10 jpeg objects 5. HTTP server closes TCP connection. Application Layer 22

Response time modeling Definition of RRT: time to send a small packet 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 initiate TCP connection RTT request file RTT file received time time time to transmit file Application Layer 23

Persistent HTTP and Pipelining Nonpersistent HTTP issues: Requires 2 RTTs per object OS must work and allocate host resources for each TCP connection Browsers often open parallel TCP connections to fetch referenced objects Persistent HTTP Server leaves connection open after sending response Subsequent HTTP messages between same client/server are sent over connection Persistent without pipelining: Client issues new request only when previous response has been received One RTT for each referenced object Persistent with pipelining: Default in HTTP/1.1 Client sends requests as soon as it encounters a referenced object As little as one RTT for all the referenced objects Application Layer 24

Number of Objects Per Page Cummulative Probability Number of objects per page Application Layer 25

HTTP request message Two types of HTTP messages: request, response HTTP request message: ASCII (human-readable format) request line (GET, POST, HEAD commands) header lines GET /somedir/page.html HTTP/1.1 Host: www.someschool.edu User-agent: Mozilla/4.0 Connection: close Accept-language:fr Carriage return, line feed indicates end of message (extra carriage return, line feed) Application Layer 26

HTTP request message: general format Application Layer 27

Uploading form input Post method: Web page often includes form input Input is uploaded to server in entity body URL method: Uses GET method Input is uploaded in URL field of request line: www.somesite.com/animalsearch?monkeys&banana Application Layer 28

Method types HTTP/1.0 GET POST HEAD Asks server to leave requested object out of response HTTP/1.1 GET, POST, HEAD PUT Uploads file in entity body to path specified in URL field DELETE Deletes file specified in the URL field Application Layer 29

HTTP response message status line (protocol status code status phrase) header lines server will close connection after response msg HTTP/1.1 200 OK Connection close Date: Thu, 06 Aug 1998 12:00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998... Content-Length: 6821 Content-Type: text/html data, e.g., requested HTML file data data data data data... Application Layer 30

HTTP response status codes In first line in server->client response message. A few sample codes: 200 OK request succeeded, requested object later in this message 301 Moved Permanently requested object moved, new location specified later in this message (Location:) 400 Bad Request request message not understood by server 404 Not Found requested document not found on this server 505 HTTP Version Not Supported Application Layer 31

User-server interaction: authorization Authorization : Control access to server content Authorization credentials: typically name, password Stateless: client must present authorization in each request Authorization: header line in each request If no authorization: header, server refuses access, sends WWW authenticate: header line in response client usual http request msg 401: authorization req. WWW authenticate: usual http request msg + Authorization: <cred> usual http response msg usual http request msg + Authorization: <cred> usual http response msg server time Application Layer 32

Cookies: keeping state Many Web sites use cookies Four components: 1) Cookie header line in the HTTP response message 2) Cookie header line in HTTP request message 3) Cookie file kept on user s host and managed by user s browser 4) Back-end database at Web site Example: Susan access Internet always from same PC She visits a specific e- commerce site for first time When initial HTTP requests arrives at site, site creates a unique ID and creates an entry in backend database for ID Application Layer 33

Cookies: keeping state (cont.) Cookie file ebay: 8734 Client usual http request msg usual http response + Set-cookie: 1678 Server server creates ID 1678 for user entry in backend database Cookie file amazon: 1678 ebay: 8734 one week later: usual http request msg cookie: 1678 usual http response msg cookiespecific action access access Cookie file amazon: 1678 ebay: 8734 usual http request msg cookie: 1678 usual http response msg cookiespectific action Application Layer 34

Cookies & Privacy What cookies can bring: Authorization Shopping carts Recommendations User session state (Web e-mail) Cookies and privacy: Cookies permit sites to learn a lot about you You may supply name and e-mail to sites Search engines use redirection & cookies to learn yet more Advertising companies obtain info across sites Application Layer 35

Conditional GET: client-side caching Goal: don t send object if client has up-to-date cached version Client: specify date of cached copy in HTTP request If-modified-since: <date> Client HTTP request msg If-modified-since: <date> HTTP response HTTP/1.0 304 Not Modified Server object not modified Server: response contains no object if cached copy is upto-date: HTTP/1.0 304 Not Modified HTTP request msg If-modified-since: <date> HTTP response HTTP/1.0 200 OK <data> object modified Application Layer 36

Web caches (proxy server) Goal: satisfy client request without involving origin server User sets browser: Web accesses via cache Browser sends all HTTP requests to cache Object in cache: cache returns object Else cache requests object from origin server, then returns object to client client client HTTP request HTTP response HTTP request HTTP response Proxy server HTTP request HTTP response origin server origin server Application Layer 37

HTTP Summary Client Server Protocol Pull Protocol Stateless Text-based Persistent connections Pipelining Message format Method types Authorization Cookies Client-side caching Web caches Application Layer 38

Outline Principles of app layer protocols clients and servers app requirements Web and HTTP DNS Socket programming with TCP Application Layer 39

DNS: Domain Name System People Many identifiers CPR, name, passport # Hosts, routers IP address (32 bit) - used for addressing datagrams borg.cs.auc.dk - used by humans, 130.225.194.22 used by machines Domain Name System: Distributed database implemented in hierarchy of many name servers Application-layer protocol Clients and servers communicate to resolve names (address/name translation) Network service implemented on the edge of the network Application Layer 40

DNS: Domain Name System Why not centralize DNS? Single point of failure Traffic volume Distant centralized database Maintenance Political issues doesn t scale! DNS issues Name Spaces Flat Hierarchical Binding Names to values Resolution mechanism How do clients resolve a name Application Layer 41

Name Spaces. net org mil gov com edu uk dk mit unc cs med Hierarchical and abstract name space Each node corresponds to a domain Domain = a place where more names can be defined Domain names Read from right to left Example www.cs.unc.edu. www Application Layer 42

Name Servers. net org com gov mil edu uk dk Partition tree into zones A zone is an administrative authority A zone corresponds to the unit of implementation Information in each zone is implemented in two or more name servers (reliability) A server can implement several zones A hierarchy of servers mit unc cs med www Application Layer 43

Local+Authoritative Name Servers Local name servers: Each ISP, company has local (default) name server Host DNS query first goes to local name server Authoritative name server: Store mappings for a zone Can perform name/address translation for that host in its zone How can local name servers find the right authoritative name server? Root name servers Application Layer 44

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 e NASA Mt View, CA f Internet Software C. Palo Alto, CA b USC-ISI Marina del Rey, CA l ICANN Marina del Rey, CA a NSI Herndon, VA c PSInet Herndon, VA d U Maryland College Park, MD g DISA Vienna, VA h ARL Aberdeen, MD j NSI (TBD) Herndon, VA k RIPE London i NORDUnet Stockholm m WIDE Tokyo 13 root name servers worldwide F: gets 270.000.000+ hits per day.com TLD gets 5.000.000.000!! Application Layer 45

Simple DNS example Host surf.eurecom.fr wants IP address of gaia.cs.umass.edu 2 root name server 4 5 3 local name server dns.eurecom.fr authorititive name server dns.umass.edu 1 6 requesting host surf.eurecom.fr gaia.cs.umass.edu Application Layer 46

Intermediates root name server Root name server: May not know authoritative name server May know intermediate name server: who to contact to find authoritative name server local name server dns.eurecom.fr 1 2 8 requesting host surf.eurecom.fr 7 3 6 intermediate name server dns.umass.edu 4 5 authoritative name server dns.cs.umass.edu gaia.cs.umass.edu Application Layer 47

Iterated queries root name server Recursive query: Puts burden of name resolution on contacted name server Root servers have enough work to do! Iterated query: Contacted server replies with name of server to contact I don t know this name, but ask this server local name server dns.eurecom.fr 1 2 8 requesting host surf.eurecom.fr 3 4 7 iterated query intermediate name server dns.umass.edu 5 6 authoritative name server dns.cs.umass.edu gaia.cs.umass.edu Application Layer 48

Caching and updating records Caching Cache mappings to minimize traffic load Cached entries timeout after some time New DNS features from the IETF Change notification Force update of caches Update option Allow administrators to dynamically update DNS entries RFC 2136 Application Layer 49

DNS records DNS: distributed DB storing resource records (RR) RR format: (name, value, type,ttl) Type=A name is hostname value is IP address Type=NS name is domain (e.g. foo.com) value is IP address of authoritative name server for this domain Type=CNAME name is alias name for some (the real) name www.ibm.com is really servereast.backup2.ibm.com value is cannonical name Type=MX value is name of mailserver associated with name Application Layer 50

DNS protocol, messages DNS protocol : query and reply messages, both with same message format Message header Identification: 16 bit # for query, reply to query uses same # Flags: query or reply recursion desired recursion available reply is authoritative Number of Elements in the following fields Application Layer 51

DNS protocol, messages Name, type fields for a query RRsin reponse to query records for authoritative servers additional helpful info that may be used Application Layer 52

Domain Information Groper >dig www.cs.auc.dk ;; QUESTION SECTION: ;www.cs.auc.dk. IN A ;; ANSWER SECTION: www.cs.auc.dk. 86400 IN CNAME elm.cs.auc.dk. elm.cs.auc.dk. 86400 IN A 130.225.194.199 ;; AUTHORITY SECTION: cs.auc.dk. 86400 IN NS auaw.aua.auc.dk. cs.auc.dk. 86400 IN NS femto.cs.auc.dk. cs.auc.dk. 86400 IN NS ns-soa.darenet.dk. cs.auc.dk. 86400 IN NS dns.e.cs.auc.dk. cs.auc.dk. 86400 IN NS dns.cs.auc.dk. ;; ADDITIONAL SECTION: dns.e.cs.auc.dk. 86400 IN A 130.225.195.2 dns.cs.auc.dk. 86400 IN A 130.225.194.2 auaw.aua.auc.dk. 58648 IN A 130.225.54.2 femto.cs.auc.dk. 86400 IN A 130.225.194.111 ns-soa.darenet.dk. 58028 IN A 130.226.1.4 Application Layer 53

DNS Summary Key techiques that keep DNS working Hierarchy Caching Distributed processing On Monday, October 21, 2002, the Internet didn't stop. That evening, the Internet's 13 DNS root servers suffered a heavy Distributed Denial of Service (DDoS) attack that failed to disrupt service... 9 servers failed, 4 continued to work No root servers, no working Internet! Application Layer 54

Outline Principles of app layer protocols clients and servers app requirements Web and HTTP DNS Socket programming with TCP Application Layer 55

Socket programming A socket is a host-local, application-created, OScontrolled interface (a door ) into which application process can both send and receive messages to/from another application process Socket API Introduced in BSD4.1 UNIX, 1981 Explicitly created, used, released by apps Two types of transport service via socket API: Unreliable datagram (UDP) Reliable, byte stream-oriented (TCP) Application Layer 56

Socket programming Socket: a door between application process and end-end-transport protocol controlled by application developer controlled by operating system process socket TCP with buffers, variables internet process socket TCP with buffers, variables controlled by application developer controlled by operating system End-system End-system Application Layer 57

Socket programming with TCP Client must contact server Server process must first be running, and must have created socket 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 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 Application Layer 58

Socket programming with TCP Client Process Server Process Welcoming Socket Client Socket Connection Socket Application Layer 59

xample client-server app Client reads line from standard input (infromuser stream), sends to server via socket (outtoserver stream) infromserver outtoserver Server reads line from socket Client socket Server converts line to uppercase, sends back to client Standard output 4) 2) 3) Client process 1) Client reads, prints modified line from socket (infromserver stream) Standard input infromuser Application Layer 60

Client/server socket interaction: TCP Server (running on borg) create socket, port=2227, for incoming request: welcomesocket = ServerSocket() wait for incoming connection request connectionsocket = welcomesocket.accept() read request from connectionsocket TCP connection setup Client create socket, connect to borg, port=2227 clientsocket = Socket() send request using clientsocket write reply to connectionsocket close connectionsocket read reply from clientsocket close clientsocket Application Layer 61

Example: Java server (I) import java.io.*; import java.net.*; class TCPServer { Create welcoming socket at port 2227 Wait for client to connect Create input stream, attached to socket public static void main(string argv[]) throws Exception { String clientsentence; String capitalizedsentence; ServerSocket welcomesocket = new ServerSocket(2227); while(true) { Socket connectionsocket = welcomesocket.accept(); BufferedReader infromclient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()) Application Layer 62

Example: Java server (II) Create output stream, attached to socket Read in line from socket DataOutputStream outtoclient = new DataOutputStream(connectionSocket.getOutputStream()); clientsentence = infromclient.readline(); capitalizedsentence = clientsentence.touppercase() + '\n'; Write out line outtoclient.writebytes(capitalizedsentence); to socket connectionsocket.close(); // close connection } // end while } // end main } // end class Application Layer 63

Example: Java client (I) import java.io.*; import java.net.*; class TCPClient { Create input stream Create client socket, connect to server Create output stream tached to socket public static void main(string argv[]) throws Exception { String sentence; String modifiedsentence; BufferedReader infromuser = new BufferedReader(new InputStreamReader(System.in)); // java gets borg s ip address using DNS Socket clientsocket = new Socket( borg", 2227); DataOutputStream outtoserver = new DataOutputStream(clientSocket.getOutputStream()); Application Layer 64

Example: Java client (II) Create input stream attached to socket Send line to server Read line from server 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(); } // end main } // end class Application Layer 65

Chapter 2: Summary Most importantly: learned about protocols Typical request/reply message exchange: client requests info or service server responds with data, status code Message formats: headers: fields giving info about data data: info being communicated centralized vs. decentralized stateless reliable vs. unreliable msg transfer complexity at network edge security: authentication Application Layer 66

socket programming in C' Primitive socket bind listen accept connect send receive close Meaning Create a new communication socket end point (specify protocol) Attach a local address to a socket Announce willingness to accept connections; give queue size Block the caller until a connection attempt arrives Actively attempt to establish a connection Send some data from the connection Receive some data from the connection Release the connection Application Layer 67

Socket programming: references C-language tutorial (audio/slides): Unix Network Programming (J. Kurose), http://manic.cs.umass.edu/~amldemo/courseware/intro.html Java-tutorial: Socket Programming in Java: a tutorial, http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets.html Application Layer 68