multiple send from server to client python

后端 未结 2 729
青春惊慌失措
青春惊慌失措 2020-12-07 06:32

First I am sending the requested file from the server to the client and after that I want to send the computed sha of the file from the server to the client, so that the cli

2条回答
  •  没有蜡笔的小新
    2020-12-07 06:48

    You should redesign a bit how your app works:

    • First the servers sends to the client the file size
    • The client reads the file size (converts it to a number) and notifies the server (sends "OK" to the server for example)
    • The server reads the "OK" from the client and starts to send the file contents (preferably in smaller chunks)
    • The client keeps reading data until either it reads exactly "file size" bytes or error occurs
    • If no error occurred the client computes the hash of the file that it just received and sends it to the server
    • The server reads the hash from client and compares with the one of its local file - if they match it sends "OK" to the client "ERROR" otherwise
    • The client reads the response from server: if "ERROR" is received the file is deleted

提交回复
热议问题