Sending a file over TCP sockets in Python

后端 未结 6 1224
太阳男子
太阳男子 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 08:53

    you may change your loop condition according to following code, when length of l is smaller than buffer size it means that it reached end of file

    while (True):
        print "Receiving..."
        l = c.recv(1024)        
        f.write(l)
        if len(l) < 1024:
            break
    

提交回复
热议问题