Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added UI/arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions UI/decoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import socket
import time
from io import BytesIO

import matplotlib.pyplot as plt
from PIL import Image

def receive_image_client(server_ip, server_port):
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((server_ip, server_port))

start_time = time.time()

image_data = b""
while True:
chunk = client_socket.recv(1024)
if not chunk:
break
image_data += chunk

end_time = time.time()
# 5 spaces(tab characters to separate image data from the start_time engraved in image)

start_time = (image_data.split(b" ")[1]).decode()
image_data = image_data.split(b" ")[0]

# Transfer time is calculated here
transfer_time = end_time - float(start_time)
received_encoded_output = BytesIO(image_data)

print(f"Image received successfully in {transfer_time} seconds")


client_socket.close()
display_received_image(image_data)



def display_received_image(image_data):
image = Image.open(BytesIO(image_data))
plt.imshow(image)
plt.title("Received Image")
plt.show()


if __name__ == "__main__":
server_ip = "10.50.25.126" # Keep the server IP here
server_port = 55555 # Random port which is free at any time

receive_image_client(server_ip, server_port)
46 changes: 46 additions & 0 deletions UI/encoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import socket
import time
import cv2

def send_image_server(ip, port, image_path):
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((ip, port))
server_socket.listen(1)

print(f"Server listening on {ip}:{port}")

while True:
data_connection, address = server_socket.accept()
print(f"Connection from {address}")

# Open the image using cv2 and resize to 256x256
try:
image = cv2.imread(image_path)
resized_image = cv2.resize(image, (256, 256)) # Use cv2 for resizing

# Convert to RGB format for byte conversion (if necessary)
if resized_image.shape[2] == 3: # Already RGB
resized_image_data = resized_image.tobytes()
else: # Convert to RGB
resized_image_data = cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB).tobytes()

except FileNotFoundError:
print(f"Error: File '{image_path}' not found.")
data_connection.close()
continue

# Combine image data with start time
start_time = time.time()
image_data_with_time = resized_image_data + b" " + (str(start_time)).encode()


# Send the combined data directly
data_connection.sendall(image_data_with_time)
data_connection.close()

if __name__ == "__main__":
server_ip = '10.50.25.126'
server_port = 55555
image_path = "./Lake.jpg"

send_image_server(server_ip, server_port, image_path)
Binary file added UI/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/id.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 133 additions & 0 deletions UI/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
from tkinter import *
import socket
from tkinter import filedialog
from tkinter import messagebox
import os

import encoder
from encoder import send_image_server

import decoder
from decoder import receive_image_client

root = Tk()
root.title("Auto Encoded File Transfer")
root.geometry("450x560+500+200")
root.configure(bg = "#f4fdfe")
root.resizable(False,False)

def Send():
window=Toplevel(root)
window.title("Send")
window.geometry("450x560+500+200")
window.configure(bg="#f4fdfe")
window.resizable(False,False)

def select_file():
global filename
filename = filedialog.askopenfilename(initialdir=os.getcwd(),
title='Select file',
filetypes = (('file_type','*.txt'),('all files','*.*')))

def sender():
s=socket.socket()
host=socket.gethostname()
port=12345
s.bind((host,port))
s.listen(1)
print(host)
print('Waiting for incoming connections...')
conn,addr=s.accept()
file=open(filename,'rb')
file_data=file.read(4096)
send_image_server(file_data)
conn.send(file_data)
print("File has been transferred successfully")

#icon
image_icon1 = PhotoImage(file = "/home/eshaiyer/tkinter/send.png")
window.iconphoto(False,image_icon1)

Sbackground = PhotoImage(file = "/home/eshaiyer/tkinter/sender.png")
Label(window,image=Sbackground).place(x=2,y=0)

Mbackground = PhotoImage(file = "/home/eshaiyer/tkinter/id.png")
Label(window,image=Mbackground,bg="#f4fdfe").place(x=100,y=260)

host=socket.gethostname()
Label(window,text=f'ID:{host}',bg='white',fg='black').place(x=140,y=290)

Button(window,text="+ select file",width=10,height=1,font='arial 14 bold',bg="#fff",fg="#000",command = select_file).place(x=160,y=150)
Button(window,text="SEND",width=8,height=1,font='arial 14 bold',bg='#000',fg='#fff',command = sender).place(x=300,y=150)

window.mainloop()

def Receive():
main=Toplevel(root)
main.title("Receive")
main.geometry("450x560+500+200")
main.configure(bg="#f4fdfe")
main.resizable(False,False)

def receiver():
ID=SenderID.get()
filename1=incoming_file.get()

s=socket.socket()
port=12345
s.connect((ID,port))
file=open(filename1,'wb')
file_data=s.recv(4096)
receive_image_client(file_data)
file.write(file_data)
file.close()
print("File has been received successfully")

#icon
image_icon1 = PhotoImage(file = "/home/eshaiyer/tkinter/receive.png")
main.iconphoto(False,image_icon1)

Hbackground=PhotoImage(file = "/home/eshaiyer/tkinter/receiver.png")
Label(main,image=Hbackground).place(x=-2,y=0)

Label(main,text="Receive",font=('arial',20),bg="#f4fdfe").place(x=100,y=280)

Label(main,text="Enter Sender ID",font=('arial',10,'bold'),bg="#f4fdfe").place(x=20,y=340)
SenderID = Entry(main,width=25,fg="black",border=2,bg='white',font=('arial',15))
SenderID.place(x=20,y=370)
SenderID.focus()

Label(main,text="Filename for incoming file",font=('arial',10,'bold'),bg="#f4fdfe").place(x=20,y=420)
incoming_file = Entry(main,width=25,fg="black",border=2,bg='white',font=('arial',15))
incoming_file.place(x=20,y=450)

imageicon = PhotoImage(file = "/home/eshaiyer/tkinter/arrow.png")
rr=Button(main,text="Receive",compound=LEFT,image=imageicon,width=130,bg="#39c790",font="arial 14 bold",command=receiver)
rr.place(x=20,y=500)

main.mainloop()

#icon
image_icon = PhotoImage(file = "/home/eshaiyer/tkinter/icon.png")
root.iconphoto(False,image_icon)

Label(root,text="File Transfer",font=('Acumin Variable Concept',20,'bold'),bg="#f4fdfe").place(x=20,y=30)

Frame(root,width=400,height=2,bg="#f3f5f6").place(x=25,y=80)

send_image = PhotoImage(file = "/home/eshaiyer/tkinter/send.png")
send = Button(root,image = send_image,bg = "#f4fdfe", bd = 0,command = Send)
send.place(x=50,y=100)

receive_image = PhotoImage(file = "/home/eshaiyer/tkinter/receive.png")
receive = Button(root,image = receive_image,bg = "#f4fdfe", bd = 0, command = Receive)
receive.place(x=300,y=100)

#label
Label(root,text="Send",font=('Acumin Variable Concept',17,'bold'),bg = "#f4fdfe").place(x=65,y=200)
Label(root,text="Receive",font=('Acumin Variable Concept',17,'bold'),bg = "#f4fdfe").place(x=300,y=200)

background = PhotoImage(file = "/home/eshaiyer/tkinter/background.png")
Label(root,image=background).place(x=2,y=323)

root.mainloop()
Binary file added UI/receive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/receiver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/send.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/sender.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions decoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import socket
import time
from io import BytesIO

import matplotlib.pyplot as plt
from PIL import Image

def receive_image_client(server_ip, server_port):
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((server_ip, server_port))

start_time = time.time()

image_data = b""
while True:
chunk = client_socket.recv(1024)
if not chunk:
break
image_data += chunk

end_time = time.time()
# 5 spaces(tab characters to separate image data from the start_time engraved in image)

start_time = (image_data.split(b" ")[1]).decode()
image_data = image_data.split(b" ")[0]

# Transfer time is calculated here
transfer_time = end_time - float(start_time)
received_encoded_output = BytesIO(image_data)

print(f"Image received successfully in {transfer_time} seconds")


client_socket.close()
display_received_image(image_data)



def display_received_image(image_data):
image = Image.open(BytesIO(image_data))
plt.imshow(image)
plt.title("Received Image")
plt.show()


if __name__ == "__main__":
server_ip = "10.50.25.126" # Keep the server IP here
server_port = 55555 # Random port which is free at any time

receive_image_client(server_ip, server_port)
46 changes: 46 additions & 0 deletions encoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import socket
import time
import cv2

def send_image_server(ip, port, image_path):
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((ip, port))
server_socket.listen(1)

print(f"Server listening on {ip}:{port}")

while True:
data_connection, address = server_socket.accept()
print(f"Connection from {address}")

# Open the image using cv2 and resize to 256x256
try:
image = cv2.imread(image_path)
resized_image = cv2.resize(image, (256, 256)) # Use cv2 for resizing

# Convert to RGB format for byte conversion (if necessary)
if resized_image.shape[2] == 3: # Already RGB
resized_image_data = resized_image.tobytes()
else: # Convert to RGB
resized_image_data = cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB).tobytes()

except FileNotFoundError:
print(f"Error: File '{image_path}' not found.")
data_connection.close()
continue

# Combine image data with start time
start_time = time.time()
image_data_with_time = resized_image_data + b" " + (str(start_time)).encode()


# Send the combined data directly
data_connection.sendall(image_data_with_time)
data_connection.close()

if __name__ == "__main__":
server_ip = '10.50.25.126'
server_port = 55555
image_path = "./Lake.jpg"

send_image_server(server_ip, server_port, image_path)
40 changes: 40 additions & 0 deletions receiver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import tkinter as tk
from tkinter import filedialog
import socket
import os
import decoder
from decoder import receive_image_client

def receive_file():
host = '0.0.0.0'
port = 5555

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((host, port))
server_socket.listen(1)

conn, addr = server_socket.accept()

data = conn.recv(1024).decode()
file_name, file_size = data.split(':')

file_path = filedialog.asksaveasfilename(defaultextension='.*', initialfile=file_name)
if file_path:
with open(file_path, 'wb') as file:
while True:
file_data = conn.recv(1024)
if not file_data:
break
file.write(file_data)

conn.close()
server_socket.close()
print('File received successfully')

root = tk.Tk()
root.title('File Receiver')

receive_file_button = tk.Button(root, text='Receive File', command=receive_file)
receive_file_button.pack(pady=20)

root.mainloop()
Loading