說明
1. 在瀏覽器中輸入一個網(wǎng)址時潦俺,需要將它先解析出ip地址來
2. 當(dāng)?shù)玫絠p地址之后,瀏覽器以tcp的方式3次握手鏈接服務(wù)器
3. 以tcp的方式發(fā)送http協(xié)議的請求數(shù)據(jù)給服務(wù)器
4. 服務(wù)器tcp的方式回應(yīng)http協(xié)議的應(yīng)答數(shù)據(jù)給瀏覽器
總結(jié)
1. MAC地址:在設(shè)備與設(shè)備之間數(shù)據(jù)通信時用來標(biāo)記收發(fā)雙方(網(wǎng)卡的序列號)
2. IP地址:在邏輯上標(biāo)記一臺電腦,用來指引數(shù)據(jù)包的收發(fā)方向(相當(dāng)于電腦的序列號)
3. 網(wǎng)絡(luò)掩碼:用來區(qū)分ip地址的網(wǎng)絡(luò)號和主機號
4. 默認(rèn)網(wǎng)關(guān):當(dāng)需要發(fā)送的數(shù)據(jù)包的目的ip不在本網(wǎng)段內(nèi)時,就會發(fā)送給默認(rèn)的一臺電腦拓劝,成為網(wǎng)關(guān)
5. 集線器:已過時,用來連接多態(tài)電腦嘉裤,缺點:每次收發(fā)數(shù)據(jù)都進(jìn)行廣播郑临,網(wǎng)絡(luò)會變的擁堵
6. 交換機:集線器的升級版,有學(xué)習(xí)功能知道需要發(fā)送給哪臺設(shè)備屑宠,根據(jù)需要進(jìn)行單播厢洞、廣播
7. 路由器:連接多個不同的網(wǎng)段,讓他們之間可以進(jìn)行收發(fā)數(shù)據(jù)典奉,每次收到數(shù)據(jù)后躺翻,ip不變,但是MAC地址會變化
8. DNS:用來解析出IP(類似電話簿)
9. http服務(wù)器:提供瀏覽器能夠訪問到的數(shù)據(jù)
網(wǎng)絡(luò)傳輸模型
網(wǎng)際層也稱為:網(wǎng)絡(luò)層
網(wǎng)絡(luò)接口層也稱為:鏈路層
另外一套標(biāo)準(zhǔn)
反射卫玖,四個方法公你,hasattr,getattr,setattr,delattr,一切皆對象
http://www.cnblogs.com/linhaifeng/articles/6204014.html
__setattr__, __delattr__, __getattr__
實例化后增加假瞬,修改陕靠,獲取屬性時會觸發(fā) class 中的這些屬性迂尝,具體可以看
http://www.cnblogs.com/linhaifeng/articles/6204014.html
class Earth:
start = 0
def __init__(self, name):
self.name = name
def __getattr__(self, item):
print('this is getattr')
e = Earth('bbs')
print(e.name)
e.x #獲取一個不存在的屬性,觸發(fā)__getattr__
輸出結(jié)果:
bbs
this is getattr
獲取類的屬性
class Earth:
start = 0
def __init__(self, name):
self.name = name
def __getattr__(self, item):
print('this is getattr')
print(Earth.__dict__) #獲取的屬性不完整
print(dir(Earth)) #獲取所有的屬性
輸出結(jié)果:
{'__module__': '__main__', 'start': 0, '__init__': <function Earth.__init__ at 0x000001AE1FC64620>, '__getattr__': <function Earth.__getattr__ at 0x000001AE1FC646A8>, '__dict__': <attribute '__dict__' of 'Earth' objects>, '__weakref__': <attribute '__weakref__' of 'Earth' objects>, '__doc__': None}
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'start']
包裝標(biāo)準(zhǔn)類型
class List(list): #繼承并修改 list 方法
def show_list(self):
for i in self:
print(i, end='')
print('')
def append(self, object):
print('append the', object)
if type(object) == str:
super(List, self).append(object) #調(diào)用父類
else:
print('only append str')
l = List('www.baidu.com')
l.show_list()
l.append(123)
l.append('www.google.com')
print(l)
輸出結(jié)果:
www.baidu.com
append the 123
only append str
append the www.google.com
['w', 'w', 'w', '.', 'b', 'a', 'i', 'd', 'u', '.', 'c', 'o', 'm', 'www.google.com']
授權(quán)剪芥,也就是在 class 中調(diào)用類似于父類的方法和屬性垄开,但不繼承于父類
import time
class open_file():
def __init__(self, filename, mode='r', encoding='utf-8'):
self.file = open(filename, mode, encoding=encoding) #直接調(diào)用 open 方法
self.mode = mode
self.encoding = encoding
def write(self, item):
print(item)
t = time.strftime('%Y-%m-%d %X')
self.file.write('%s %s' %(t, item)) #用實例的文件類 self.file 操作
def read(self):
print(self.file.read()[0:20]) #截出時間戳
def __getattr__(self, item):
print(item)
return getattr(self.file, item) #返回屬性調(diào)用
f = open_file('a.txt', 'w+', 'utf-8')
f.write('ni hao ma')
f.seek(0)
f.read()
輸出結(jié)果:
ni hao ma
seek
2018-04-17 00:18:06