이 코드에는 몇 가지 문제가 있습니다 ... 정수 이미지가 아닌 몇 바이트를 보내주십시오. 도와 줄 수있는 사람이 있습니까? 폴더에서 찾은 모든 이미지를 보내려고합니다. 고맙습니다.소켓을 사용하여 이미지 보내기 Python
CLIENT
import socket
import sys
import os
s = socket.socket()
s.connect(("localhost",9999)) #IP address, port
sb = 'c:\\python27\\invia'
os.chdir(sb) #path
dirs =os.listdir(sb) #list of file
print dirs
for file in dirs:
f=open(file, "rb") #read image
l = f.read()
s.send(file) #send the name of the file
st = os.stat(sb+'\\'+file).st_size
print str(st)
s.send(str(st)) #send the size of the file
s.send(l) #send data of the file
f.close()
s.close()
SERVER
import socket
import sys
import os
s = socket.socket()
s.bind(("localhost",9999))
s.listen(4) #number of people than can connect it
sc, address = s.accept()
print address
sb = 'c:\\python27\\ricevi'
os.chdir(sb)
while True:
fln=sc.recv(5) #read the name of the file
print fln
f = open(fln,'wb') #create the new file
size = sc.recv(7) #receive the size of the file
#size=size[:7]
print size
strng = sc.recv(int(size)) #receive the data of the file
#if strng:
f.write(strng) #write the file
f.close()
sc.close()
s.close()
그래서 문제가 무엇이고 질문이 무엇입니까? – kirelagin
어떻게 이미지의 실제 바이트를 보내고받을 수 있습니까? .. 다른 폴더에서 이미지를 복사하고 싶기 때문에 os.stat 또는 os.getsize 함수가 잘 작동하지 않습니다. 코드는 매우 간단하지만 정확히 작동하지 않는 이유를 모르겠다. –
그래서 "파이썬 소켓이 파일 보내기"에 대한 인터넷 검색을 시도 했습니까? – kirelagin