[go: up one dir, main page]

0% found this document useful (0 votes)
12 views13 pages

Chapter 2 Part4

The document provides an overview of the application layer in networking, covering topics such as P2P applications, web protocols like HTTP, and email protocols like SMTP and IMAP. It explains socket programming with both UDP and TCP, detailing how client/server interactions occur and providing example applications in Python. Key themes include the differences between reliable and unreliable data transfer, as well as the importance of various protocols and architectures in network applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views13 pages

Chapter 2 Part4

The document provides an overview of the application layer in networking, covering topics such as P2P applications, web protocols like HTTP, and email protocols like SMTP and IMAP. It explains socket programming with both UDP and TCP, detailing how client/server interactions occur and providing example applications in Python. Key themes include the differences between reliable and unreliable data transfer, as well as the importance of various protocols and architectures in network applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Application Layer: Overview

 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with UDP
 E-mail, SMTP, IMAP and TCP
 The Domain Name System
DNS

Application Layer: 2-1


Socket programming
goal: learn how to build client/server applications that communicate
using sockets
socket: door between application process and end-end-transport
protocol

application application
socket controlled by
process process app developer

transport transport
network network controlled
link
by OS
link Internet
physical physical

Application Layer: 2-2


Socket programming
Two socket types for two transport services:
 UDP: unreliable datagram
 TCP: reliable, byte stream-oriented

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-3


Socket programming with UDP
UDP: no “connection” between client and
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 processes
Application Layer: 2-4
Client/server socket interaction: UDP
server (running on serverIP) client

create socket:
create socket, port= x: clientSocket =
serverSocket = socket(AF_INET,SOCK_DGRAM)
socket(AF_INET,SOCK_DGRAM)
Create datagram with serverIP address
And port=x; send datagram via
read datagram from clientSocket
serverSocket

write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket
Application Layer: 2-5
Example app: UDP client
Python UDPClient
include Python’s socket library from socket import *
serverName = ‘hostname’
serverPort = 12000
create UDP socket for server clientSocket = socket(AF_INET,
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 socket into string
modifiedMessage, serverAddress =
clientSocket.recvfrom(2048)
print out received string and close socket print modifiedMessage.decode()
clientSocket.close()

Application Layer: 2-6


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 message, clientAddress = serverSocket.recvfrom(2048)
client’s address (client IP and port)
modifiedMessage = message.decode().upper()
send upper case string back to this client serverSocket.sendto(modifiedMessage.encode(),
clientAddress)

Application Layer: 2-7


Socket programming with TCP
Client must contact server when contacted by client, server TCP
 server process must first be creates new socket for server process to
communicate with that particular client
running allows server to talk with multiple clients
 server must have created socket source port numbers used to distinguish
(door) that welcomes client’s clients (more in Chap 3)
contact
Client contacts server by:
 Creating TCP socket, specifying IP
address, port number of server
process
 when client creates socket: client Application viewpoint
TCP establishes connection to TCP provides reliable, in-order
server TCP byte-stream transfer (“pipe”)
between client and server
processes
Application Layer: 2-8
Client/server socket interaction: TCP
server (running on hostid) client

create socket,
port=x, for incoming
request:
serverSocket = socket()

wait for incoming create socket,


connection request
TCP connect to hostid, port=x
connectionSocket = connection setup clientSocket = socket()
serverSocket.accept()

send request using


read request from clientSocket
connectionSocket

write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
Application Layer: 2-9
Example app: TCP client
Python TCPClient
from socket import *
serverName = ’servername’
serverPort = 12000
create TCP socket for server, clientSocket = socket(AF_INET, SOCK_STREAM)
remote port 12000
clientSocket.connect((serverName,serverPort))
sentence = raw_input(‘Input lowercase sentence:’)
clientSocket.send(sentence.encode())
No need to attach server name, port modifiedSentence = clientSocket.recv(1024)
print (‘From Server:’, modifiedSentence.decode())
clientSocket.close()

Application Layer: 2-10


Example app: TCP server
Python TCPServer
from socket import *
serverPort = 12000
create TCP welcoming socket serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind((‘’,serverPort))
server begins listening for
incoming TCP requests
serverSocket.listen(1)
print ‘The server is ready to receive’
loop forever while True:
server waits on accept() for incoming connectionSocket, addr = serverSocket.accept()
requests, new socket created on return

read bytes from socket (but sentence = connectionSocket.recv(1024).decode()


not address as in UDP) capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence.
encode())
close connection to this client (but not connectionSocket.close()
welcoming socket)
Application Layer: 2-11
Chapter 2: Summary
our study of network application layer is now complete!

 application architectures  specific protocols:


• client-server • HTTP
• P2P • SMTP, IMAP
 application service requirements: • DNS
• P2P: BitTorrent
• reliability, bandwidth, delay
 video streaming, CDNs
 Internet transport service model  socket programming:
• connection-oriented, reliable: TCP, UDP sockets
TCP
• unreliable, datagrams: UDP

Application Layer: 2-12


Chapter 2: Summary
Most importantly: learned about protocols!
 typical request/reply message important themes:
exchange:  centralized vs. decentralized
• client requests info or service  stateless vs. stateful
• server responds with data, status  scalability
code  reliable vs. unreliable message
 message formats: transfer
 “complexity at network edge”
• headers: fields giving info about data
• data: info(payload) being
communicated

Application Layer: 2-13

You might also like