I am trying to send an image file using socket programming in python. I am able to send a text file. But I have been trying to send an image file, by opening it and reading
I ran the same code on my system (Ubuntu 11.10) and I found that, there is a problem with sending size as a string. When I inserted logic to handle that part, it ran smoothly. I could open the file also. This is how I could solve your problem : 1st change in client code(client.py) is while accepting size and sending acknowledgement about it :-
size = ' '
while(1):
tmpsize = client_socket.recv(1)
if tmpsize.isdigit() == True:
print "Here : ",tmpsize
size += tmpsize
else:
break
client_socket.send("received")
2nd change is in server side(server.py) code, to accept acknowledgement :-
client_socket.send(size)
ack = client_socket.recv(1024)
if ack == "received":
client_socket.send (strng)
I hope this will help you to solve your problem.