SlideShare a Scribd company logo
Application Layer 2-1
Chapter 2: outline
2.1 principles of network
applications
 app architectures
 app requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS
2.6 P2P applications
2.7 socket programming
with UDP and TCP
Application Layer 2-2
Socket programming
goal: learn how to build client/server applications that
communicate using sockets
socket: door between application process and end-end-
transport protocol
Internet
controlled
by OS
controlled by
app developer
transport
application
physical
link
network
process
transport
application
physical
link
network
process
socket
Application Layer 2-3
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 the data to the server.
2. The server receives the data and converts
characters to uppercase.
3. The server sends the modified data to the client.
4. The client receives the modified data and displays
the line on its screen.
Application Layer 2-4
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
 rcvr 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
Client/server socket interaction: UDP
close
clientSocket
read datagram from
clientSocket
create socket:
clientSocket =
socket(AF_INET,SOCK_DGRAM)
Create datagram with server IP and
port=x; send datagram via
clientSocket
create socket, port= x:
serverSocket =
socket(AF_INET,SOCK_DGRAM)
read datagram from
serverSocket
write reply to
serverSocket
specifying
client address,
port number
Application 2-5
server (running on serverIP) client
Application Layer 2-6
Example app: UDP client
from socket import *
serverName = ‘hostname’
serverPort = 12000
clientSocket = socket(socket.AF_INET,
socket.SOCK_DGRAM)
message = raw_input(’Input lowercase sentence:’)
clientSocket.sendto(message,(serverName, serverPort))
modifiedMessage, serverAddress =
clientSocket.recvfrom(2048)
print modifiedMessage
clientSocket.close()
Python UDPClient
include Python’s socket
library
create UDP socket for
server
get user keyboard
input
Attach server name, port to
message; send into socket
print out received string
and close socket
read reply characters from
socket into string
Application Layer 2-7
Example app: UDP server
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('', serverPort))
print “The server is ready to receive”
while 1:
message, clientAddress = serverSocket.recvfrom(2048)
modifiedMessage = message.upper()
serverSocket.sendto(modifiedMessage, clientAddress)
Python UDPServer
create UDP socket
bind socket to local port
number 12000
loop forever
Read from UDP socket into
message, getting client’s
address (client IP and port)
send upper case string
back to this client
Application Layer 2-8
Socket programming with TCP
client must contact server
 server process must first be
running
 server must have created
socket (door) that
welcomes client’s contact
client contacts server by:
 Creating 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 that
particular client
 allows server to talk with
multiple clients
 source port numbers used
to distinguish clients (more
in Chap 3)
TCP provides reliable, in-order
byte-stream transfer (“pipe”)
between client and server
application viewpoint:
Application Layer 2-9
Client/server socket interaction: TCP
wait for incoming
connection request
connectionSocket =
serverSocket.accept()
create socket,
port=x, for incoming
request:
serverSocket = socket()
create socket,
connect to hostid, port=x
clientSocket = socket()
server (running on hostid) client
send request using
clientSocket
read request from
connectionSocket
write reply to
connectionSocket
TCP
connection setup
close
connectionSocket
read reply from
clientSocket
close
clientSocket
Application Layer 2-10
Example app: TCP client
from socket import *
serverName = ’servername’
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = raw_input(‘Input lowercase sentence:’)
clientSocket.send(sentence)
modifiedSentence = clientSocket.recv(1024)
print ‘From Server:’, modifiedSentence
clientSocket.close()
Python TCPClient
create TCP socket for
server, remote port 12000
No need to attach server
name, port
Application Layer 2-11
Example app: TCP server
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()
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)

More Related Content

PPT
Socket Programming_theory.ppt
PPTX
Basics of Socket Programming using python
PPTX
Networking in Python2025 (programs allll)
PPTX
Transport Layer and Client-Server Socket communications 2022.pptx
PPT
Ch2 application layer Network
PPT
applicationapplicationapplicationapplication.ppt
PPT
Chapter2_L2.ppt
PPT
Chapter2 l2 modified_um
Socket Programming_theory.ppt
Basics of Socket Programming using python
Networking in Python2025 (programs allll)
Transport Layer and Client-Server Socket communications 2022.pptx
Ch2 application layer Network
applicationapplicationapplicationapplication.ppt
Chapter2_L2.ppt
Chapter2 l2 modified_um

Similar to Chapter_2_part5.ppt in the department of computer science (20)

PPT
Lecture-2012-2-Application Layer-Introduction.ppt
PPT
Application Layer.pptand documents of co
PPT
Chapter_2_V6.1._C__hapter_2_V6.1____.ppt
PPTX
Computer Network presentation chapter two
PPT
Hasanain_Application Layer_Chapter_2_Version 7.1.ppt
PPTX
Chapter_2_v8.3.pptx
PPT
Chapter 2 - Computer Networking a top-down Approach 7th
PPTX
Chapter_2 jaringan komputer informatika.pptx
PPT
Chapter 2 Application Layer Computer Networks
PPT
principles of network applications 2.2 Web and HTTP 2.3 electronic mail SMTP,...
PPTX
Net_Chapter_2_ computer network-software.pptx
PPTX
kkkkkkkkkkkkkkkkkkkmkm,kll;kl;l;l;l;lll;l;l;;;
PPTX
Network programming using python
PPT
Application Layer-Introduction - detail Things are included
PPTX
Ci hy Jo is type ki videos edit krei Inbox kro mujhe with similar portfolio ...
PPT
Socket programming-tutorial-sk
PPT
Chapter2 Application
PDF
Socket programming using java
PPTX
02_Chapter_2_V6_LV.pptx
PPT
Chapter 2 v6.3
Lecture-2012-2-Application Layer-Introduction.ppt
Application Layer.pptand documents of co
Chapter_2_V6.1._C__hapter_2_V6.1____.ppt
Computer Network presentation chapter two
Hasanain_Application Layer_Chapter_2_Version 7.1.ppt
Chapter_2_v8.3.pptx
Chapter 2 - Computer Networking a top-down Approach 7th
Chapter_2 jaringan komputer informatika.pptx
Chapter 2 Application Layer Computer Networks
principles of network applications 2.2 Web and HTTP 2.3 electronic mail SMTP,...
Net_Chapter_2_ computer network-software.pptx
kkkkkkkkkkkkkkkkkkkmkm,kll;kl;l;l;l;lll;l;l;;;
Network programming using python
Application Layer-Introduction - detail Things are included
Ci hy Jo is type ki videos edit krei Inbox kro mujhe with similar portfolio ...
Socket programming-tutorial-sk
Chapter2 Application
Socket programming using java
02_Chapter_2_V6_LV.pptx
Chapter 2 v6.3
Ad

Recently uploaded (20)

PDF
PPT Determiners.pdf.......................
PPTX
1.pptxsadafqefeqfeqfeffeqfqeqfeqefqfeqfqeffqe
PDF
Cableado de Controladores Logicos Programables
PPTX
INFERTILITY (FEMALE FACTORS).pptxgvcghhfcg
PPTX
Fundamentals of Computer.pptx Computer BSC
PPTX
Prograce_Present.....ggation_Simple.pptx
PPTX
Syllabus Computer Six class curriculum s
PPTX
5. MEASURE OF INTERIOR AND EXTERIOR- MATATAG CURRICULUM.pptx
PPTX
Operating System Processes_Scheduler OSS
PPTX
Wireless and Mobile Backhaul Market.pptx
PPTX
quadraticequations-111211090004-phpapp02.pptx
PDF
Layer23-Switch.com The Cisco Catalyst 9300 Series is Cisco’s flagship stackab...
PPTX
Embedded for Artificial Intelligence 1.pptx
PPTX
PLC ANALOGUE DONE BY KISMEC KULIM TD 5 .0
PPT
Hypersensitivity Namisha1111111111-WPS.ppt
PPTX
Entre CHtzyshshshshshshshzhhzzhhz 4MSt.pptx
PPTX
material for studying about lift elevators escalation
PPTX
Presentacion compuuuuuuuuuuuuuuuuuuuuuuu
PPTX
Lecture 3b C Library _ ESP32.pptxjfjfjffkkfkfk
PPTX
02fdgfhfhfhghghhhhhhhhhhhhhhhhhhhhh.pptx
PPT Determiners.pdf.......................
1.pptxsadafqefeqfeqfeffeqfqeqfeqefqfeqfqeffqe
Cableado de Controladores Logicos Programables
INFERTILITY (FEMALE FACTORS).pptxgvcghhfcg
Fundamentals of Computer.pptx Computer BSC
Prograce_Present.....ggation_Simple.pptx
Syllabus Computer Six class curriculum s
5. MEASURE OF INTERIOR AND EXTERIOR- MATATAG CURRICULUM.pptx
Operating System Processes_Scheduler OSS
Wireless and Mobile Backhaul Market.pptx
quadraticequations-111211090004-phpapp02.pptx
Layer23-Switch.com The Cisco Catalyst 9300 Series is Cisco’s flagship stackab...
Embedded for Artificial Intelligence 1.pptx
PLC ANALOGUE DONE BY KISMEC KULIM TD 5 .0
Hypersensitivity Namisha1111111111-WPS.ppt
Entre CHtzyshshshshshshshzhhzzhhz 4MSt.pptx
material for studying about lift elevators escalation
Presentacion compuuuuuuuuuuuuuuuuuuuuuuu
Lecture 3b C Library _ ESP32.pptxjfjfjffkkfkfk
02fdgfhfhfhghghhhhhhhhhhhhhhhhhhhhh.pptx
Ad

Chapter_2_part5.ppt in the department of computer science

  • 1. Application Layer 2-1 Chapter 2: outline 2.1 principles of network applications  app architectures  app requirements 2.2 Web and HTTP 2.3 FTP 2.4 electronic mail  SMTP, POP3, IMAP 2.5 DNS 2.6 P2P applications 2.7 socket programming with UDP and TCP
  • 2. Application Layer 2-2 Socket programming goal: learn how to build client/server applications that communicate using sockets socket: door between application process and end-end- transport protocol Internet controlled by OS controlled by app developer transport application physical link network process transport application physical link network process socket
  • 3. Application Layer 2-3 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 the data to the server. 2. The server receives the data and converts characters to uppercase. 3. The server sends the modified data to the client. 4. The client receives the modified data and displays the line on its screen.
  • 4. Application Layer 2-4 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  rcvr 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
  • 5. Client/server socket interaction: UDP close clientSocket read datagram from clientSocket create socket: clientSocket = socket(AF_INET,SOCK_DGRAM) Create datagram with server IP and port=x; send datagram via clientSocket create socket, port= x: serverSocket = socket(AF_INET,SOCK_DGRAM) read datagram from serverSocket write reply to serverSocket specifying client address, port number Application 2-5 server (running on serverIP) client
  • 6. Application Layer 2-6 Example app: UDP client from socket import * serverName = ‘hostname’ serverPort = 12000 clientSocket = socket(socket.AF_INET, socket.SOCK_DGRAM) message = raw_input(’Input lowercase sentence:’) clientSocket.sendto(message,(serverName, serverPort)) modifiedMessage, serverAddress = clientSocket.recvfrom(2048) print modifiedMessage clientSocket.close() Python UDPClient include Python’s socket library create UDP socket for server get user keyboard input Attach server name, port to message; send into socket print out received string and close socket read reply characters from socket into string
  • 7. Application Layer 2-7 Example app: UDP server from socket import * serverPort = 12000 serverSocket = socket(AF_INET, SOCK_DGRAM) serverSocket.bind(('', serverPort)) print “The server is ready to receive” while 1: message, clientAddress = serverSocket.recvfrom(2048) modifiedMessage = message.upper() serverSocket.sendto(modifiedMessage, clientAddress) Python UDPServer create UDP socket bind socket to local port number 12000 loop forever Read from UDP socket into message, getting client’s address (client IP and port) send upper case string back to this client
  • 8. Application Layer 2-8 Socket programming with TCP client must contact server  server process must first be running  server must have created socket (door) that welcomes client’s contact client contacts server by:  Creating 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 that particular client  allows server to talk with multiple clients  source port numbers used to distinguish clients (more in Chap 3) TCP provides reliable, in-order byte-stream transfer (“pipe”) between client and server application viewpoint:
  • 9. Application Layer 2-9 Client/server socket interaction: TCP wait for incoming connection request connectionSocket = serverSocket.accept() create socket, port=x, for incoming request: serverSocket = socket() create socket, connect to hostid, port=x clientSocket = socket() server (running on hostid) client send request using clientSocket read request from connectionSocket write reply to connectionSocket TCP connection setup close connectionSocket read reply from clientSocket close clientSocket
  • 10. Application Layer 2-10 Example app: TCP client from socket import * serverName = ’servername’ serverPort = 12000 clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverName,serverPort)) sentence = raw_input(‘Input lowercase sentence:’) clientSocket.send(sentence) modifiedSentence = clientSocket.recv(1024) print ‘From Server:’, modifiedSentence clientSocket.close() Python TCPClient create TCP socket for server, remote port 12000 No need to attach server name, port
  • 11. Application Layer 2-11 Example app: TCP server 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() 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)