아래 코드에서 한 컴퓨터의 파이썬 소켓 모듈을 사용하여 이미지를 다른 컴퓨터로 보내려고했습니다. 그래서 2 개의 파일이 있습니다 : client.py와 Server.py
내가 알아 낸대로 문제는 클라이언트 컴퓨터에서 이미지 (바이트)를 읽은 다음 서버가 파일을 받으려고 할 때 수신 프로세스 전에 전송 프로세스가 완료되면 다음 오류가 줄에 발생합니다. 13 클라이언트 코드 :
BrokenPipeError: [Errno 32] Broken pipe
이 오류가 무엇인지, 왜 내 코드에서 발생하는지 알고 싶습니다.
Server.py
import socket
host = '192.168.1.35'
port = 5000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(1)
while True:
conn , addr = s.accept()
data = conn.recv(1024)
with open(r"C:\Users\master\Desktop\music.jpg",'wb') as f:
f.write(data)
# conn.send(b'done')
data = conn.recv(1024)
if not data:
break
conn.send(b'done')
conn.send(b'done')
conn.close()
s.close()
Client.py
import socket
def main():
HOST = '192.168.1.35'
PORT = 5000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
f = open('/home/taha/Desktop/f.jpg','rb')
data = f.read()
s.sendfile(f)
if s.recv(1024) == b'done':
f.close()
s.close()
if __name__ == '__main__':
main()
클라이언트가 "완료"를 읽기 전에 서버 연결을 닫습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다