我试图从服务器读取图像文件,代码如下。它总是进入例外。我知道发送的字节数是正确的,因为我在接收时将它们打印出来。我从python发送图像文件#open the image file and read it into an object
imgfile = open (marked_image, 'rb')
obj = imgfile.read()
#get the no of bytes in the image and convert it to a string
bytes = str(len(obj))
#send the number of bytes
self.conn.send( bytes + '\n')
if self.conn.sendall(obj) == None:
imgfile.flush()
imgfile.close()
print 'Image Sent'
else:
print 'Error'
这是安卓系统的部分,这就是我的问题所在。关于接收图像并将其写入文件的最佳方法有何建议?在
^{pr2}$
编辑:我似乎还是不能让它工作。我从那以后就一直在做,我所有努力的结果要么导致了一个不是完整大小的文件,要么就是应用程序崩溃。我知道在发送服务器端之前文件没有损坏。据我所知,它肯定也在发送,因为python中的send all方法在发生错误时发送all或抛出异常,到目前为止它还没有抛出异常。所以客户端一团糟。我必须从服务器发送文件,这样我就不能使用Brian的建议了。在