server:
importsocket,os,hashlib
server=socket.socket()
server.bind((
"localhost
",9999))#
繫結要監聽的埠
server.listen()#
開始監聽
while
true:
conn,addr=server.accept()#
等待使用者輸入命令
print("
newconn
",addr)
while
true:
print("
等待新指令")
data=conn.recv(1024)
ifnot
data:
print("
客戶端斷開")
break
cmd,filename=data.decode().split()
(filename)
ifos.path.isfile(filename):
f = open(filename,"rb"
) m =hashlib.md5()
file_size=os.stat(filename).st_size
conn.send(str(file_size).encode())
#send file size
conn.recv(1024)#
wait for ack
for line in
f: m.update(line)
conn.send(line)
print("
file md5
",m.hexdigest())
f.close()
conn.send(m.hexdigest().encode())
#send md5
print("
send done")
server.close()
client:
importsocket,os,hashlib
client=socket.socket()
client.connect((
"localhost
",9999))
while
true:
cmd = input("
>>:
".strip())
if len(cmd) ==0:continue
if cmd.startswith("
get"
): client.send(cmd.encode())
server_respose=client.recv(1024)#
檔案大小
print("
server respose
",server_respose)
client.send(b
"ready to recv file")
file_total_size =int(server_respose.decode())
received_size=0
filename=cmd.split()[1]
f = open(filename+"
.new
","wb
")#複製新檔案
m =hashlib.md5()
while received_sizeif file_total_size - received_size > 1024:#
接收不止一次
size=1024
else:#
最後一次接收
size=file_total_size-received_size
print("
last receive
",size)
data=client.recv(size)
received_size+=len(data)
m.update(data)
f.write(data)
else
: new_file_md5=m.hexdigest()
print("
file recv done
",received_size,file_total_size)
f.close()
server_file_md5=client.recv(1024)#
最後接收伺服器返回的md5
print("
server file md5
",server_file_md5)
print("
client file md5
",new_file_md5)
client.close
Numpy函式cumsum之分分鐘理解
二 cumsum函式理解別廢話,觀察 思考 1 案例 import numpy as np arr np.arange 1,48,2 reshape 2,3,4 print arr 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 4...
分分鐘搞定python破解無線wifi
大家可以根據自己放的文職進行輸入命令 coding utf 8 import time 時間 import pywifi 破解wifi from pywifi import const 引用一些定義 from asyncio.tasks import sleep class pojie def in...
教你分分鐘搞定Python之Flask框架
用最短的時間開發乙個資料操作介面,python是王道!一 安裝pip 1 首先檢查linux有沒有安裝python pip包,終端執行 pip v root network scripts pip v bash pip command not found 2 沒有python pip包就執行命令 y...