在我的代码中,我将图像从客户端发送到服务器。一切都运行良好,但是当我尝试将图像的文件名从服务器发送到客户端时,我一直在等待,我没有得到任何错误。 这是我的代码:
客户端:
import socket
import pickle
host = socket.gethostname()
port = 5000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host , port))
f = open("test.png", "rb")
while True:
veri = f.read()
if not veri:
break
s.send(veri)
f.close()
print "image successfully sent"
data = s.recv(1024)
#data_arr=pickle.loads(data)
print "data recieved is :",data
s.close()
服务器:
import socket
import pickle
from PIL import Image
import os
host = socket.gethostname()
port = 5000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
s.listen(5)
client , adress = s.accept()
print "successfully connected to",adress
f = open("server.png", "wb")
while True:
veri = client.recv(1024)
if not veri:
break
f.write(veri)
f.close()
print "image recieved successfully"
T= os.path.abspath(f.name)
print "the path of the image is ",T
#data=pickle.dumps(T)
client.send(T)
print "binary data sent"
client.close()