-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.py
41 lines (29 loc) · 1.01 KB
/
receiver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import socket
import os
import tkinter as tk
from tkinter import filedialog
s = socket.socket()
#host = input("\nEnter the sender ip address: ")
host = "192.168.20.146"
port = 12345
s.connect((host, port))
print('Connected to sender')
file_size_bytes = s.recv(8)
file_size = int.from_bytes(file_size_bytes, byteorder='big')
file_obj = filedialog.asksaveasfile(
defaultextension="*.*", # Default extension if none provided by the user
filetypes=[("Select extension (FileType)","*.*"), ("Text", "*.txt"), ("JPG", ".jpg"), ("PNG", ".png"), ("PDF",".pdf"), ("GIF", ".gif"),
("MP3",".mp3"), ("MP4",".mp4")] # Dropdown menu options
)
filename = file_obj.name if file_obj else None
if filename:
with open(filename, 'wb') as f:
while True:
data = s.recv(1024)
if not data:
break
f.write(data)
print('File received successfully')
else:
print('File saving canceled by user')
s.close()