Chapter 2.4-2.7
Chapter 2.4-2.7
Application Layer
above lets you send email without using email client (reader)
… …
m. WIDE Tokyo
e. NASA Mt View, CA (5 other sites)
f. Internet Software C.
Palo Alto, CA (and 48 other sites)
gaia.cs.umass.edu
type=A type=CNAME
name is hostname name is alias name for some
value is IP address “ canonical” (the real) name
www.ibm.com is really
type=NS
• name is domain (e.g., servereast.backup2.ibm.com
foo.com) value is canonical name
• value is hostname of
authoritative name type=MX
server for this domain value is name of mailserver
associated with name
2 bytes 2 bytes
identification flags
application application
socket controlled by
process process app developer
transport transport
network network controlled
link
by OS
link Internet
physical physical
Application Example:
1. client reads a line of characters (data) from its
keyboard and sends data to server
2. server receives the data and converts characters to
uppercase
3. server sends modified data to client
4. client receives modified data and displays line on
its screen
Application Layer 2-31
Socket programming with UDP
UDP: no “ connection” between client & server
no handshaking before sending data
sender explicitly attaches IP destination address and
port # to each packet
receiver extracts sender IP address and port# from
received packet
UDP: transmitted data may be lost or received
out-of-order
Application viewpoint:
UDP provides unreliable transfer of groups of bytes (
“ datagrams” ) between client and server
write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket
Application 2-33
Example app: UDP client
Python UDPClient
include Python’s socket
library from socket import *
serverName = ‘hostname’
serverPort = 12000
create UDP socket for clientSocket = socket(AF_INET,
server
SOCK_DGRAM)
get user keyboard
input message = raw_input(’Input lowercase sentence:’)
Attach server name, port to
message; send into socket
clientSocket.sendto(message.encode(),
(serverName, serverPort))
read reply characters from
modifiedMessage, serverAddress =
socket into string
clientSocket.recvfrom(2048)
print out received string
and close socket
print modifiedMessage.decode()
clientSocket.close()
Application Layer 2-34
Example app: UDP server
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
while True:
Read from UDP socket into
message, getting client’s
message, clientAddress = serverSocket.recvfrom(2048)
address (client IP and port) modifiedMessage = message.decode().upper()
send upper case string serverSocket.sendto(modifiedMessage.encode(),
back to this client
clientAddress)
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket