Sending Multiple Files Python Using Socket

前端 未结 2 785
借酒劲吻你
借酒劲吻你 2021-01-16 08:34

I currently am trying to create a client-server application in which the client can send multiple files to the server using TCP protocol. The server will eventually create a

2条回答
  •  北海茫月
    2021-01-16 09:07

    1. file_size = conn.recv(1024) In your server code you read 1024 bytes as your file_size, file_size is only 4 or 8 bytes long

    2. file_name = conn.recv(1024) Your server don't know how long the filename/hashtype is.

    -> Use a long for both sizes and read only sizeof(long) bytes from the stream.

    You can use https://docs.python.org/2/library/struct.html for packing/encoding of these numbers

    -> Or just go the easy way and use https://docs.python.org/3/library/pickle.html for serialization

提交回复
热议问题