为什么我的客户端不会在这个while循环中突破?(客户端服务器文件传输)

时间:2017-03-10 06:06:37

标签: file sockets server client transfer

我在客户端的代码中有这个,它向服务器发送请求以发送文件。

客户端:

    filetoopen = tokens[1]
    msg = "RETR " + filetoopen
    sock.send( msg.encode() )
    file2 = open( filetoopen , "w")`

    while True:

        file = sock.recv(1024).decode()

        if(not file or file == '' or len(file) <= 0 ):

            file2.close()
            break
        else:

            file2.write(file) 
            print(file) 

    print("FILE : " , file)
    print("\n File [ " + filetoopen + " ] has been transfered to the current working directory")
    print("from the remote server.\n")

SERVER:

    openfile = open(file , "r")
    file = openfile.read()

    while (file != ''):
        sock.send(file.encode())
        file = openfile.read()

    openfile.close()

    print("CLOSED FILE")

(&#39; file&#39;是作为参数发送的文件名)

0 个答案:

没有答案