Sending a file over TCP sockets in Python

后端 未结 6 1225
太阳男子
太阳男子 2020-12-02 08:14

I\'ve successfully been able to copy the file contents (image) to a new file. However when I try the same thing over TCP sockets I\'m facing issues. The server loop is not e

6条回答
  •  爱一瞬间的悲伤
    2020-12-02 09:01

    The problem is extra 13 byte which server.py receives at the start. To resolve that write "l = c.recv(1024)" twice before the while loop as below.

    print "Receiving..."
    l = c.recv(1024) #this receives 13 bytes which is corrupting the data
    l = c.recv(1024) # Now actual data starts receiving
    while (l):
    

    This resolves the issue, tried with different format and sizes of files. If anyone knows what this starting 13 bytes refers to, please reply.

提交回复
热议问题