multiple send from server to client python

后端 未结 2 705
青春惊慌失措
青春惊慌失措 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
    0 讨论(0)
  • 2020-12-07 06:55

    A TCP stream needs to be formatted in both ends, since it is a stream not packets. I suppose you could look for a nullbyte ('\x00') which should signal end of file.

    0 讨论(0)
提交回复
热议问题