应用层——HTTP/SMTP/DNS/FTP$套接字UDP/TCP

1. Web和HTTP:

  1. cookie
  2. web缓存
  3. conditional Get:方法:Get+if-Modified-since

2. SMTP原理

smtp接受

  1. 实验之telnet:
    1. telnet serverName 25
    在这里插入图片描述
  2. email reportcontent format:
From:
To:
Subject:Hello,smtp
  1. POP3&IMAP&基于Web(email服务器->emaii代理,为pull 协议;而smtp为push 协议)
    1. POP3 极简smtp
    2. IMAP 在远程服务器上创建自己的文件夹,可取部分传输信息
    3. 基于web
      接收: ClientBrowser<(http)-clientEmail<(smtp)-serveiceemail
      send: clientBrowser-(http)>serviceemail

3. DNS_因特网的目录服务_initial encounter with a database

简单查询
递归查询
0. 实验之wireshark

  1. DNS的vulnerability
  2. layer structure: root dns>top-level dns>authority dns
  3. dns cache,like web dns
  4. Resource Record:(Name, Value,Type,TTL)

4. P2P文件分发

  1. Server-Client system:T分发=max(\(\frac {F} {d_{min}}, \frac {NF}{u_s})\)
  2. client join in 分发: T分发=max(\(\frac {F} {d_{min}},\frac {F} {u_s} ,\frac {NF} {us+\sum_{i=1}^N u_i}\))
    在这里插入图片描述
  3. example:Bittorrent 协议——download part that is used least(visit tracker)

5. CDN_Content Distribution Network

  1. DASH_Dynamic Adaptive Streaming over HTTP
  2. Google's network =百万数据中心(动态内容)+(集群(static)+'enter-deep')
  3. CDN基本过程

  4. 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:

  1. Web server
  2. UDP Ping
  3. email client
  4. Multi-process Web-Agent Server
  5. Wireshark
posted @ 2022-09-22 18:59  clfire  阅读(24)  评论(0编辑  收藏  举报