Application layer protocols principle
1, application architecture Architecture file application (end system how to organize applications)
Client - server client-server: Fixed known IP, data center
P2P: traffic-intensive, since extended, highly decentralized
2, interprocess communication
C / S: C initiating communication, downloading; S waits contact, upload
Application Program Interface / socket (interface between the application layer and the transport layer) : Alternatively, the development of some of the parameters
Addressing: IP, port number http://www.iana.org
3, transport services
Reliable data transfer: ensure data delivery
Throughput: the bit rate of transmission to the receiving process of the delivery process; at a particular rate to ensure that the available throughput
Timing: To be effective and deliver the data required strict time limits
Security: encryption, endpoint authentication, data integrity
4, the transport layer protocol
TCP: connection-oriented; reliable data transfer; Congestion Control
SSL: TCP enhanced version; encryption, endpoint authentication, data integrity
UDP: connectionless; no-frills; arbitrary data injection rate
Transport protocol does not provide the service: throughput timing; firewall blocks UDP traffic, TCP backup
5, the application layer protocol (RFC public domain documents, private protocol)
Message type; packet syntax; semantic field; response rule
Web and HTTP (RFC 2616) 80 port
Web page: HTML, JPEG, Java files; HTTP: Hypertext Transfer Protocol HyperText Transfer Protocol
Web browser (IE, Firefox), Web server (Apache, MIIS)
Stateless stateless protocol: do not store any customer information
1, continuous / non-continuous connection
Default HTTP persistent connection, the configuration may be non-continuous; default browser opens 5 to 10 concurrent TCP connection, a parallel connection response times
Length persistent connection: in response to a request by the same TCP connection; non-continuous non-persistent: single TCP connection
RTT: round trip time Round-Trip Time = propagation delay + delay + Queuing delay processing; Fair 2 * RTT + file transfer time
HTTP1.1: Timeout closes the connection; HTTP / 2 (RFC 7540): Mechanism of Q
2, HTTP message format
request:
Code:
// request line GET /somedir/page.html HTTP / 1.1 // requests an object // header line Host: www.someschool.edu // Host, Web proxy cache requirements Connection: use Close the User -agent: Mozilla / 5.0 / / user agent, browser type the Accept-Language: fr // etc.
POST: form generation request message ( GET + Extended URL)
HEAD: request packet does not return the request object
PUT: Upload objects
DELETE: delete an object
response:
Code:
// status line the HTTP / 1.1 200 is the OK // protocol version, status code, state information // header line Connection: Close a Date: Tue, 18 is -Aug , 2015 15 : 44 is : 04 GMT // send a response time of packets Server: Apache / 2.2 . . 3 (the CentOS) last -Modified: Tue, 18 is -Aug , 2015 15 : . 11 : 03 GMT // created or last modified date of the Content-the Length: 6821 // number of bytes in the Content-the Type: text / HTM L //Object type // solid body (the Data the Data the Data the Data ...) // message
200 OK: Request successful
301 Moved Permanently: Object has been permanently transferred
400 Bad Request: request can not be understood by the server
404 Not Found: Documents that are not on the server
505 HTTP Version Not Supported: HTTP protocol version does not support
Use telnet (RFC 854) program can log on to the Web server:
telnet gaia.cs.umass.edu 80 GET /kurose_ross/interactive/index.php HTTP/1.1 Host: gaia.cs.umass.edu
(End user can enter commands in the telnet program, these commands will run on the server, just as input directly on the server console may be able to control the server locally. To start a telnet session, you must enter a user name and password to login server .Telnet is a common method of remote control of the Web server.)
3、cookie (RFC 6265)
(HTTP stateless server simplifies the design, the user can be identified using a cookie.)
cookie technology components: HTTP response header row; the HTTP request header row; cookie folder client system; the Web site database
4, Web Cache
(Also known as a proxy server.)
Definition: The Web server can represent the initial meet network entity of the HTTP request. Web caching is generally purchased and installed by the ISP.
Reason: the object quickly delivered to the user; means to reduce the traffic of the Internet access;
CDN: CDN
5, conditional GET
(Updated copy of the cache problem)
// 1. Request packet the GET /fruit/kiwi.gif the HTTP / 1.1 the Host: www.exotiquecuisine.com // response message the HTTP / 1.1 200 is the OK a Date: Sat, . 3 On Oct , 2015 15 : 39 : 29 Server: the Apache / 1.3 . 0 (Unix) Last -Modified: Wed, 9 Sep 2015 09 : 23 : 24- Content -Type: Image / GIF (the Data the Data the Data the Data ...) // 2. "conditions" request message GET / fruit / HTTP kiwi.gif / 1.1 The Host: www.exotiquecuisine.com the If -modefied-Operating since: Wed, . 9 On Sep , 2015 09 : 23 is : 24 // response message the HTTP / 1.1 304 Not Modified // no improvement, updating a Date: Sat, 10 On Oct , 2015 15 : 39 : 29 Server: the Apache / 1.3 . 0 (Unix) (empty the Entity body)
Email and SMTP (RFC 5321) 25 port
(Asynchronous communication medium) components: User Agent User Agent; mail server mail server; SMTP, Simple Mail Transfer Protocol Simple Mail Transfer Protocol;
HTTP mainly pull protocol (pull protocol): the user using HTTP pull information from the server; the HTTP package each object to its own HTTP response packet;
SMTP is basically a push protocol (push protocol): the file is pushed to the receiving mail server; SMTP message to all objects in a message being;
1、SMTP
Limit 7-bit ASCII portion of said multimedia codec required. Usually the intermediate SMTP server to send mail message is not used. SMTP is a persistent connection.
SMTP handshake protocol:
S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MALL FROM: <[email protected]> S: 250 [email protected] ... Sender ok C: RCPT TO: <[email protected]> S: 250 [email protected] ... Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Do you like ketchup? C: How about pickles? C: . S: 250 Message accepted for delivery C: QUIT S: 221 hamburger.edu closing connection
Line message headers:
From: [email protected] To: [email protected] Subject: Searching for the meaning of life.
Telnet program:
telnet serverName 25
2. Message Access Protocol
Mail access using C / S architecture.
(Alice's user agent using SMTP e-mail push her mail server, mail server and then she SMTP, Bob will relay messages to the mail server, by Bob Special Message Access Protocol, pull the mail.)
POP3 (RFC 1939) 110 port, the third edition of the Post Office Protocol
Work components: Chartered (user identification); transaction processing (fetch returns the text, remove the mark); update (server to delete the marked packets);
Chartered:
MailServer Telnet 110 + OK READY the POP3 Server User Bob + OK Pass Hungry + OK User successfully logged ON // + OK command preceding the normal @ preceding command error -ERR
Transaction:
C: List S: . 1 498 // stored packet length S: 2 912 S:. C: RETR . 1 S: (...) S:. C: DELE . 1 C: RETR 2 S: (...) S:. C: DELE 2 C: quit S: + the OK OFF the POP3 Server Signing
IMAP (RFC 3501), Internet Mail Access Protocol
Create a remote server for user-level folder. IMAP IMAP server maintains session state information of the user. It allows the user agent to obtain only certain parts of the message.
HTTP, Web-based e-mail
And his remote user via HTTP-mail communications.
DNS (RFC 1034/1035) 53 port
Domain Name System Domain Name System. BIND DNS server software is usually running UNIX machines. UDP protocol, C / S mode, end to end transport protocol.
Method of identifying a host: hostname / IP address
Host Alias: Host complicated hostname can have multiple aliases, aliases are easier to remember than the canonical host name
Mail Server Alias: MX record allows a company's mail server and Web server using the same host alias
Load distribution: IP address associated with a set of canonical host name, redundant DNS servers distribute the load cycle
1, DNS working mechanism
Distributed hierarchical database
No one DNS server has mapped all hosts on the Internet.
Root DNS server: root DNS server TLD server IP address, the plurality of servers 400 managed by the 13 different tissues
Top-Level Domain TLD DNS server: TLD server provides authoritative DNS server IP addresses, each top-level domain (com, org, net, edu, gov) and all national top-level domain (uk, fr, ca, jp) has TLD server
Authoritative DNS server: DNS server authoritative collection of accessible DNS records for each organization to provide these records to map host names to IP addresses
Local DNS server (LDNS): DNS each ISP has a local DNS server, the host sends a request by the agent sent to the local DNS server DNS server hierarchy
Recursive query / iterative query: request from the host to the local DNS server is recursive, the rest of the query is iterative
Registration agency
ICANN authorization to various registration bodies. http://www.internic.net
DNS dynamic update (RFC 2136/3007). Provide your primary and secondary authoritative DNS server name and IP address, you can register a domain name to the DNS system.
(networkutopia.com, dns1.networkutopia.com, NS) (dns1.networkutopia.com, 212,212 . 212.1 , A)
DNS cache
DNS caching can mapped cache in a local memory. Since the mapping is not permanent, DNS server, after a certain period of time (days), cache information is discarded. So you can bypass the local DNS root and TLD DNS server. DNS adds robustness to some extent.
2, DNS records and messages
RR, the Record resource records Resourse: (the Name, Value, Type, TTL) // record TTL is time to live
Name and Value depend on Type:
Type = A: (Name: host name, Value: IP address) standard host name to IP address mapping //(relay1.bar.foo.com,145.37.93.126,A)
Type = NS: (Name: field, Value: authoritative DNS server host name) query IP addresses in the domain where the authoritative DNS server // (foo.com, dns.foo.com, NS)
Type = CNAME: (Name: The canonical host name, Value: Alias) query specification hostname //(foo.com,relay1.bar.foo.com,CNAME)
Type = MX: (Name: The canonical host name, Value: alias) mail server and other servers have the same alias //(foo.com,mail.bar.foo.com,MX)
DNS queries and answers have the same message:
Identifier: matching request and reply; signs :( query, 0) (answer 1) (authority) (hope recursion);
Use nslookup program, it can send a DNS query messages directly to certain DNS server.
P2P file distribution
A host connected to the pair of intermittently communicate directly with each other.
1. Scalability
Distribution time: all N peers get a copy of the documents of the time, D_cs vs D_p2p
D_cs >= max{ NF/us,F/dmin }
Server: minimum time distribution of NF ( 'bit) / US (upload rates)
Peers: access to documents shortest time F / dmin (minimum download speed)
D_p2p >= max{ F/us,F/dmin,NF/(us+ui) }
Server: Distribution minimum time F. ( 'Bit) / US (upload rates)
Peers: access to documents shortest time F / dmin (minimum download speed)
Overall system: the minimum time distribution of NF / (US + UI) (total upload capacity)
2、BitTorrent
Torrent: all peers to participate in a specific set of file distribution side
Block: peer file exchange with each other (typically 256KB), and also download upload
Tracker: infrastructure nodes torrent, registration and periodic inspection peer
Most scarce priority: neighbors at least a copy of the request block priority
Clear :( swapping algorithm) periodically calculating and adjusting the set of other parties, giving priority to the highest data rate request, the other peer is blocked ( "a Tit")
Video streaming and content distribution network
The DASH, by dynamic HTTP adaptive streaming Dynamic Adaptive Streaming over HTTP: video is encoded as different versions of video segment data block in response to customer requests dynamically. HTTP server in the notification file URL and a bit rate for each version, the block algorithm to select the next customer request, allowing customers to freely switch the DASH different quality levels determined by the speed.
CDN, content distribution network Content Distribution Network: CDN store a copy of the server and each user is directed to the best of CDN position.
1、CDN
Resettlement principles:
Depth: server clusters deployed in the ISP access, improved latency and throughput, but difficult to maintain and manage
Invited guest: a small amount of IXP in the construction of large clusters, low maintenance and administrative overhead, slightly lower throughput delay
Operation: Using DNS intercept and redirect the request.
Cluster selection strategy: a little (mostly speak too messy ...)
2, Netflix, YouTube, and see
Netflix: directly inform customers use a special CDN server, using the DASH adaptive streaming. Netflix CDN use push caching.
YouTube: using DNS redirection, use HTTP streaming, cluster selection strategy RTT balance and average load. Google CDN using pull cache.
Look: Mixed CDN-P2P streaming system. Customers receive from the beginning of the CDN, when total P2P traffic for video playback, the customer flow is obtained only from peers.
Socket programming py
1、UDP
client:
from socket import * serverName = 'hostname' serverPort = 12000 clientSocket = socket(AF_INET, SOCK_DGRAM) //IPv4, UDP message = raw_input('Input lowercase sentence :') clientSocket.sendto(message.encode(), (serverName,serverPort)) modifiedMessage, serverAddress = clientSocket.recvfrom(2048) print(modifiedMessage.decode()) clientSocket.close()
server:
from socket import * serverPort = 12000 serverSocket = socket(AF_INET, SOCK_DGRAM) //IPv4, UDP serverSocket.bind((' ', serverPort)) print("The server is ready to receive ") while True: message, clientAddress = serverSocket.recvfrom(2048) modifiedMessage = message.decode().upper() serverSocket.sendto(modifiedMessage.encode(), clientAddress)
2、TCP
client:
from socket import * serverName = 'servername' serverPort = 12000 clientSocket = socket(AF_INET, SOCK_STREAM) //TCP clientSocket.connect((serverName, serverPort)) sentence = raw_input('Input lowercase sentence :') clientSocket.send(sentence.encode()) modifiedSentence = clientSocket.recv(1024) print('From Server :', modifiedSentence.decode()) clientSocket.close()
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 True: connectionSocket, addr = serverSocket.accept() sentence = connectionSocket.recv(1024).decode() capitalizedSentence = sentence.upper() connectionSocket.send(capitalizedSentence.encode()) connectionSocket.close()