Skip to content Skip to sidebar Skip to footer

Send And Receive A File In Python Sockets

This has for the most part been answered here I have been trying to modify the server (to send) and client (to receive) feedback from the server upon receipt of the entire file. be

Solution 1:

Your client must indicate, somehow, that the entire file has been sent. As it stands, your server has no way of knowing when the client's send operations are complete.

One solution is to call socket.shutdown after all transmissions are complete. Here is a new version of your client program. No changers were required to your server program.

#client
import socket
s = socket.socket()
s.connect(("localhost",3000))
f=open ("tranmit.jpg", "rb")
l = f.read(1024)
while (l):
    s.send(l)
    l = f.read(1024)
s.shutdown(socket.SHUT_WR)
reply =s.recv(1024) # Feedback: would like the receive feedback from the server.
print reply
s.close()

Post a Comment for "Send And Receive A File In Python Sockets"