0

I have a server, which has 20+ clients connected to it. I want it to update those clients if needed. The solutions I've found were too complex, or simply didn't work, so I thought it might work:

  1. Server reads "client.py" and sends it through socket.
  2. Client accepts data, creates dir "update", saves file there and run bash script.
  3. Bash scripts stops client, deletes it, and move new client from /update to main dir.

The thing is it works in ~70% cases. Client usually works fine after update. The problem is in 30% client receive only part of the file. Lets say my client is 5kB, 70% of clients are fine, 30% receives only 4 kB and ofc can't run anymore.

Server:

def updateClient(self):
        try:
            file = open(str(pathlib.Path(_file_).parent.resolve())+"/client.py", "r")
            newcl = file.read()
            for host in self.active_connections:
                try:
                    host.connection.send(newcl.encode())
                except Exception as e:
                    print("[!]Error!: " + str(e))

Client:

            data = s.recv(8192)
            data = data.decode()
            newdir_path = str(pathlib.Path(_file_).parent.resolve())
            newcl_path = newdir_path+"/update/client.py"
            try:                
                os.mkdir(newdir_path+"/update")        
                print("Update directory created")
                file = open(newcl_path, 'w')
                file.write(data)
                file.close()
                print("[*] Update downloaded!")
                try:
                    process = subprocess.run("update.sh", shell=False, check=True)
                except Exception as e:
                    print(str(e))
SanDev
  • 15
  • 4

0 Answers0