I've created a chat room in python using socket (a server, any number of clients) the thing is that everything works flawlessly until a client sends a file, even the file transfer is completed on both the ends but the server side just freezes, i confirmed it by using print statement after the file transfer loop the client side seems to print it whereas on the server side i get no output. I am attaching those file transfer parts alone from both server and client side....
CLIENT SIDE:
def sendfile(self):
while True:
SEPARATOR='<SEPARATOR>'
abc='file'
filename=askopenfile(mode='rb')
filename=os.path.abspath(filename.name)
filesize=os.path.getsize(filename)
client.send(f"{abc}{SEPARATOR}{filename}{SEPARATOR}{filesize}".encode())
with open(filename,'rb')as f:
while True:
bytes_read=f.read(20480)
if not bytes_read:
break
client.sendall(bytes_read)
progress.update(len(bytes_read))
print('uploading completed')
break
SERVER SIDE:
def handle(client):
def filereceive(ms):
while True:
waste,filename,filesize=ms.split(SEPARATOR)
filename=os.path.basename(filename)
filename=filename[:-4]+'COOPY'+filename[-4:]
filesize=int(filesize)
with open(filename,'wb')as f:
while True:
bytes_read=client.recv(20480)
if not bytes_read:
break
f.write(bytes_read)
print('completed')
handle(client)
break
In short in the Server side it never prints completed which signifies its stuck there, eventhough the file transfer is completed. Kindly help me with this.........