Chapter 2 Part4
Chapter 2 Part4
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 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
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()
create socket,
port=x, for incoming
request:
serverSocket = socket()
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()