I have made a simple server -client code in python socket programming. Client side takes the screenshot(image) of its side and send it to server. It works fine when i am transferring image using 'localhost' i.e from one folder to other.....but the main problem comes when image is transferred to another computer...the received image on server side is corrupted...further more i have observed that the difference between client(sender side image i.e non corrupted one) and server(receivers side image i.e corrupted one ) is almost 1Kb every time.........
my code for client (sender) side is--
os.system('scrot screen.bmp') #command to take screen shot
FILE = "screen.bmp"
f = open(FILE, "rb")
data = f.read()
f.close()
del f
imagesize = int(os.path.getsize('screen.bmp'))
sendsize = '%1024s' %imagesize
s.sendall(str(sendsize))
print 'length of data = ',len(data)
s.sendall(str(len(data)))
s.sendall(str(data))
and server side(receiver side) ---
filename='screen.bmp'
print '[Media] Starting media transfer for ',filename
os.system('rm -f screen.bmp')
f = open(filename,"wb")
expsizeimage = int(conn.recv(1024))
data1 = conn.recv(1024)
data2=''
for i in range(0,len(data1)):
if(not(data1[i]=='0' or data1[i]=='1' or data1[i]=='2' or data1[i]=='3' or data1[i]=='4' or data1[i]=='5' or data1[i]=='6' or data1[i]=='7' or data1[i]=='8' or data1[i]=='9')):
break
data2=data2+data1[i]
print '------------'+data2+'-------------'+str(m)+'----------------'
print 'size of data:' ,int(data2)
print 'the expected size of image is: ', expsizeimage
data=9
del data
sized=0;
while 1:
data = conn.recv(expsizeimage)
print 'received length of image = ',len(data)
f.write(data)
sized=sized+len(data)
print "sized------"+str(sized)
del data
if(sized>=int(data2)):
break
print "saved the screentshot data recieved"