我想從服務器發送到客戶端的PNG圖像(屏幕截圖)。發送一個PNG文件與TCP連接
我解碼並將解碼後的字符串發送到客戶端,客戶端用它將圖像保存到他的電腦中。
但我的形象從客戶得到的是不完美的,在所有...
客戶
while "finish" not in data:
data += receive(data_len)
data = data[:-7]
fh = open("imageToSave.png", "wb")
fh.write(data.decode('base64'))
fh.close()
服務器
ImageGrab.grab().save("screen_capture.png", "PNG")
#Convert the image to a string that it will be able to be send to the client
with open("screen_capture.png", "rb") as imageFile:
Image_Str = base64.b64encode(imageFile.read())
fh = open("text", "wb")
fh.write(Image_Str)
fh.close
fh = open("text", "rb")
str1 = fh.read(150)
client_socket.send("150~" + str1)
while str1:
str1 = fh.read(150)
client_socket.send(str1)
client_socket.send("6finish")
我試圖檢查字符串相同的,它似乎是他們.. 當我嘗試解碼字符串回服務器中的圖像 - 它的工作原理...
可能字符串「完成」出現在base64編碼? – dspeyer
沒有:(我刪除.. – Maor2871