G
G
Grandma Luda2021-11-01 16:58:35
Python
Grandma Luda, 2021-11-01 16:58:35

It is incorrect to transfer data from the server to the client, what is the reason?

I want to transfer file from server to client. but some of the bytes are not transmitted

on the server by the function that transmits

async def install(self, user=None):
        if not user:
            return

        file = open(self.path_seving+"\\"+"starting.exe", "rb")
        await self.main_loop.sock_sendfile(user, file, offset=0)


on the client, a function that accepts
def install():
    data = client.recv(1024)
    file = open("starting.exe", "wb")
    file.write(data)
    while True:
        data = client.recv(1024)
        if not data: break
        file.write(data)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-11-01
@Vindicar

well, for starters, you should close the file ... best of all - through the with statement.

def install():
    with open("starting.exe", "wb") as file:
        data = client.recv(1024)
        while data:
            file.write(data)
            data = client.recv(1024)

Further, how will the client understand that everything has been transferred? By closing the connection?
So then the server should gracefully close this connection and let the client know that there will be no more data!
user.shutdown(socket.SHUT_RDWR)
user.close()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question