- 论坛徽章:
- 0
|
代码如下:
...
try:
fileStats = os.stat ( pathname ) #取文件状态
except WindowsError:
tcp_close( sockid )
raise '文件[' + pathname +']未找到'
....
cFileSize = "%08d" %fileStats[stat.ST_SIZE]
print "cFileSize[%s]" %cFileSize #此显示269字节
....
fd = open( pathname , 'r' )
sndLenSum=0
while (1):
tmpBuf = ''
tmpBuf = fd.read(512)
print "tmpBuf len[%d]" %len(tmpBuf)
if( tmpBuf == '' ): #文件读完了
break
sndLen = len( tmpBuf )
sndLenSum += sndLen
rc = tcp_write( sockid , tmpBuf , sndLen , timeout )
if( rc ):
tcp_close( sockid )
fd.close()
raise Exception('TCP 发送文件错误!' )
fd.close()
print "snd file size[%d]" %sndLenSum #此处显示263
与前面通过stat取得的269相差3字节,不知为何????
谢谢!!!
[ 本帖最后由 ibmxp 于 2007-1-18 21:00 编辑 ] |
|