应用层——HTTP/SMTP/DNS/FTP$套接字UDP/TCP
1. Web和HTTP:
- cookie
- web缓存
- conditional Get:方法:Get+if-Modified-since
2. SMTP原理
- 实验之telnet:
1. telnet serverName 25
- email reportcontent format:
From:
To:
Subject:Hello,smtp
- POP3&IMAP&基于Web(email服务器->emaii代理,为pull 协议;而smtp为push 协议)
- POP3 极简smtp
- IMAP 在远程服务器上创建自己的文件夹,可取部分传输信息
- 基于web
接收: ClientBrowser<(http)-clientEmail<(smtp)-serveiceemail
send: clientBrowser-(http)>serviceemail
3. DNS_因特网的目录服务_initial encounter with a database
0. 实验之wireshark
- DNS的vulnerability
- layer structure: root dns>top-level dns>authority dns
- dns cache,like web dns
- Resource Record:(Name, Value,Type,TTL)
4. P2P文件分发
- Server-Client system:T分发=max(\(\frac {F} {d_{min}}, \frac {NF}{u_s})\)
- client join in 分发: T分发=max(\(\frac {F} {d_{min}},\frac {F} {u_s} ,\frac {NF} {us+\sum_{i=1}^N u_i}\))
- example:Bittorrent 协议——download part that is used least(visit tracker)
5. CDN_Content Distribution Network
- DASH_Dynamic Adaptive Streaming over HTTP
- Google's network =百万数据中心(动态内容)+(集群(static)+'enter-deep')
- CDN基本过程
- CDN集群选择策略——1.地理最近(未考虑时延和带宽性质);2.based on 流量(some LDNS reluctant)
6. local UDP/TCP server+client
#udpcli
#自顶而下p111
from socket import *
serverName='***'
serverPort=12000
clientSocket=socket(AF_INET,SOCK_DGRAM)# DGRAM
message=input('input lowercase sentence:')
clientSocket.sendto(message.encode(),(serverName,serverPort))
modifiedMessage,serverAddress=clientSocket.recvfrom(2048) #serverAddress保留了服务器的地址
print(modifiedMessage.decode())
clientSocket.close()
#udpser
from socket import *
serverPort=12000
serverSocket=socket(AF_INET,SOCK_DGRAM)
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)
#tcpcli
#自顶而下p111
from socket import *
serverName='***'
serverPort=12000
clientSocket=socket(AF_INET,SOCK_STREAM)
clientSocket.connect(('serverName',serverPort))
sentence=input('Input lowercase sentence:')
clientSocket.send(sentence.encode())
modifiedSentence=clientSocket.recv(1024)
print('From Server:',modifiedSentence.decode())
clientSocket.close()
#tcpser
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()#addr保留了客户端的地址
sentence=connectionSocket.recv(1024).decode()
capitalizedSentence=sentence.upper() #转化为大写
connectionSocket.send(capitalizedSentence.encode())
connectionSocket.close() #虽然该连接关闭,serverSocket打开,仍能接受下一个客户的访问
small practice:
- Web server
- UDP Ping
- email client
- Multi-process Web-Agent Server
- Wireshark
愿偿少年泪,犹趁未老时!
本文来自博客园,作者:clfire,转载请注明原文链接:https://www.cnblogs.com/sky1water/p/16720538.html