A note on the use of these ppt slides: We’re making these slides freely available to all (faculty, students, readers). They’re in PowerPoint form so you see the animations; and 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: v If you use these slides (e.g., in a class) that you mention their source (after all, we’d like people to use our book!) v If you post any slides 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. Thanks and enjoy! JFK/KWR All material copyright 1996-2012 J.F Kurose and K.W. Ross, All Rights Reserved Application Layer 2-1 § Application Layer 2-2 v v v v v v v v v v v v v Application Layer 2-3 application transport network data link physical v v v v application transport network data link physical application transport network data link physical v Application Layer 2-4 v v § § application process socket application process transport transport network network link physical Internet link controlled by app developer controlled by OS physical Application Layer 2-5 v v v v v § § v § § § v Application Layer 2-6 v v § v v v § v v § v Application Layer 2-7 v v v v v v Application Layer 2-8 application data loss throughput time sensitive file transfer e-mail Web documents real-time audio/video no loss no loss no loss loss-tolerant stored audio/video interactive games text messaging loss-tolerant loss-tolerant no loss elastic no elastic no elastic no audio: 5kbps-1Mbps yes, 100’s msec video:10kbps-5Mbps same as above yes, few secs few kbps up yes, 100’s msec elastic yes and no Application Layer 2-9 v v v v v v v Application Layer 2-10 application e-mail remote terminal access Web file transfer streaming multimedia Internet telephony application layer protocol underlying transport protocol SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] HTTP (e.g., YouTube), RTP [RFC 1889] SIP, RTP, proprietary (e.g., Skype) TCP TCP TCP TCP TCP or UDP TCP or UDP Application Layer 2-11 § § § Application Layer 2-12 application process socket application process transport transport network network link physical Internet link controlled by app developer controlled by OS physical Application Layer 2-13 § § Application Layer 2-14 v v v v Application Layer 2-15 serverIP create socket, port= x: serverSocket = socket(AF_INET,SOCK_DGRAM) read datagram from serverSocket write reply to serverSocket specifying client address, port number create socket: clientSocket = socket(AF_INET,SOCK_DGRAM) Create datagram with server IP and port=x; send datagram via clientSocket read datagram from clientSocket close clientSocket Application 2-16 Python UDPClient include Python’s socket library from socket import * serverName = ‘hostname’ serverPort = 12000 create UDP socket for server get user keyboard input Attach server name, port to message; send into socket clientSocket = socket(socket.AF_INET, socket.SOCK_DGRAM) message = raw_input(’Input lowercase sentence:’) clientSocket.sendto(message,(serverName, serverPort)) read reply characters from socket into string modifiedMessage, serverAddress = print out received string and close socket print modifiedMessage clientSocket.recvfrom(2048) clientSocket.close() Application Layer 2-17 Python UDPServer from socket import * serverPort = 12000 create UDP socket serverSocket = socket(AF_INET, SOCK_DGRAM) bind socket to local port number 12000 serverSocket.bind(('', serverPort)) print “The server is ready to receive” loop forever Read from UDP socket into message, getting client’s address (client IP and port) send upper case string back to this client while 1: message, clientAddress = serverSocket.recvfrom(2048) modifiedMessage = message.upper() serverSocket.sendto(modifiedMessage, clientAddress) Application Layer 2-18 v v v § § v v Application Layer 2-19 hostid create socket, port=x, for incoming request: serverSocket = socket() wait for incoming TCP connection request connectionSocket = connection serverSocket.accept() read request from connectionSocket write reply to connectionSocket close connectionSocket setup create socket, connect to hostid, port=x clientSocket = socket() send request using clientSocket read reply from clientSocket close clientSocket Application Layer 2-20 Python TCPClient from socket import * serverName = ’servername’ create TCP socket for server, remote port 12000 serverPort = 12000 clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverName,serverPort)) sentence = raw_input(‘Input lowercase sentence:’) No need to attach server name, port clientSocket.send(sentence) modifiedSentence = clientSocket.recv(1024) print ‘From Server:’, modifiedSentence clientSocket.close() Application Layer 2-21 Python TCPServer create TCP welcoming socket server begins listening for incoming TCP requests loop forever server waits on accept() for incoming requests, new socket created on return read bytes from socket (but not address as in UDP) close connection to this client (but not welcoming socket) from socket import * serverPort = 12000 serverSocket = socket(AF_INET,SOCK_STREAM) serverSocket.bind((‘’,serverPort)) serverSocket.listen(1) print ‘The server is ready to receive’ while 1: connectionSocket, addr = serverSocket.accept() sentence = connectionSocket.recv(1024) capitalizedSentence = sentence.upper() connectionSocket.send(capitalizedSentence) connectionSocket.close() Application Layer 2-22