├── .gitattributes ├── README.md ├── Tux.png ├── my_client.py ├── my_server.py └── received_file.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Transfer_Image_Python_sOCKET_UserInterface 2 | Transfering images python from server to client UI python socket 3 | ![image](https://user-images.githubusercontent.com/39345855/48679945-ca193100-eb5b-11e8-9d6e-2bac2aa50301.png) 4 | 5 | Login with your credentials admin/admin 6 | 7 | ![image](https://user-images.githubusercontent.com/39345855/48679973-ea48f000-eb5b-11e8-8446-b7b6d8e83fcc.png) 8 | 9 | Says waiting for connection send a message and server will send a image to you ! ) 10 | 11 | 12 | ![image](https://user-images.githubusercontent.com/39345855/48679977-f6cd4880-eb5b-11e8-8eda-7d82eaf44c15.png) 13 | 14 | 15 | ![image](https://user-images.githubusercontent.com/39345855/48679979-fcc32980-eb5b-11e8-81f9-07f24bef1f2c.png) 16 | -------------------------------------------------------------------------------- /Tux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soumilshah1995/Transfer_Image_Python_sOCKET_UserInterface/78128924302b958c13230ea4647d736ddbf0665c/Tux.png -------------------------------------------------------------------------------- /my_client.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import messagebox 3 | import time 4 | import datetime 5 | import socket 6 | import time 7 | from time import ctime 8 | import sys 9 | from tkinter import PhotoImage 10 | LARGE_FONT= ("Verdana", 12) 11 | from tkinter import PhotoImage,BitmapImage 12 | 13 | 14 | 15 | class Page(tk.Tk): 16 | 17 | def __init__(self, *args, **kwargs): 18 | 19 | tk.Tk.__init__(self, *args, **kwargs) 20 | container = tk.Frame(self) 21 | 22 | container.pack(side="top", fill="both", expand = True) 23 | 24 | container.grid_rowconfigure(0, weight=1) 25 | container.grid_columnconfigure(0, weight=1) 26 | 27 | self.frames = {} 28 | 29 | for F in (StartPage, PageOne): 30 | 31 | frame = F(container, self) 32 | 33 | self.frames[F] = frame 34 | 35 | frame.grid(row=0, column=0, sticky="nsew") 36 | 37 | self.show_frame(StartPage) 38 | 39 | def show_frame(self, cont): 40 | 41 | frame = self.frames[cont] 42 | frame.tkraise() 43 | 44 | 45 | class StartPage(tk.Frame): 46 | 47 | def __init__(self, parent, controller): 48 | tk.Frame.__init__(self,parent) 49 | 50 | l_title=tk.Label(self, text="Client Software", 51 | font="Arial,12") 52 | l_title.grid(row=0,column=0,columnspan=3, sticky="NSEW",padx=30,pady=30) 53 | 54 | label_username = tk.Label(self, text="Username") 55 | label_password = tk.Label(self, text="Password") 56 | 57 | entry_username = tk.Entry(self,show="*") 58 | 59 | entry_password = tk.Entry(self, show="*") 60 | 61 | label_username.grid(row=2, column=0, sticky='NSEW',padx=10,pady=10) 62 | label_password.grid(row=3, column=0, sticky='NSEW',padx=10,pady=10) 63 | entry_username.grid(row=2, column=1,sticky='NSEW',padx=10,pady=10) 64 | entry_password.grid(row=3, column=1,sticky='NSEW',padx=10,pady=10) 65 | 66 | checkbox = tk.Checkbutton(self, text="Keep me logged in") 67 | checkbox.grid(row=4, column=1,sticky='NSEW',padx=10,pady=10) 68 | 69 | logbtn = tk.Button(self, text="Login", bg="BlACK", fg="White",command=lambda: login_btn_clicked()) 70 | logbtn.grid(row=5, column=1,sticky='NSEW', padx=10, pady=10) 71 | 72 | def login_btn_clicked(): 73 | # print("Clicked") 74 | username = entry_username.get() 75 | password = entry_password.get() 76 | 77 | if len(username) and len(password) > 2: 78 | # print(username, password) 79 | 80 | if username == "admin" and password == "admin": 81 | controller.show_frame(PageOne) 82 | # display a ,essage if username and password is incorrect! 83 | else: 84 | messagebox.showinfo(self,"Invalid username or password ! ") 85 | 86 | else: 87 | messagebox.showinfo(self,"Enter Username and Password") 88 | 89 | 90 | class PageOne(tk.Frame): 91 | 92 | def __init__(self, parent, controller): 93 | tk.Frame.__init__(self, parent) 94 | 95 | clock = tk.Label(self, font=('times', 18, 'bold'), bg='green',fg="white") 96 | clock.grid(row=0,column=2, sticky="NSNESWSE",padx=8,pady=8) 97 | 98 | def tick(): 99 | time2=time.strftime('%H:%M:%S') 100 | clock.config(text=time2) 101 | clock.after(200,tick) 102 | tick() 103 | 104 | label = tk.Label(self, text="Client Software ", font="Arial,16",bg="black",fg="White") 105 | label.grid(row=0, column=0, columnspan=2, padx=8, pady=8, sticky="NSNESWSE") 106 | 107 | l_host=tk.Label(self,text="Enter Host NAME") 108 | l_host.grid(row=1, column=0, padx=8, pady=8, sticky="NSNESWSE") 109 | 110 | 111 | e_host=tk.Entry(self) 112 | e_host.grid(row=1, column=1, columnspan=2, padx=8, pady=8, sticky="NSNESWSE") 113 | e_host.insert(tk.END,'127.0.0.1') 114 | 115 | 116 | l_port=tk.Label(self,text="Enter Port") 117 | l_port.grid(row=2, column=0, padx=8, pady=8, sticky="NSNESWSE") 118 | 119 | e_port=tk.Entry(self) 120 | e_port.grid(row=2, column=1, columnspan=2, padx=8, pady=8, sticky="NSNESWSE") 121 | e_port.insert(tk.END,12121) 122 | 123 | message_label=tk.Label(self,text="Server Message",font=("Arial,12")) 124 | message_label.grid(row=3,column=0,columnspan=3,padx=10,pady=10,sticky="NSEW") 125 | 126 | 127 | scrollbar_y = tk.Scrollbar(self) 128 | scrollbar_y.grid(row=4, column=3,rowspan=6) 129 | 130 | show_1=tk.Text(self,height=8, width=35, yscrollcommand=scrollbar_y.set, 131 | bg="Grey",fg="White") 132 | show_1.grid(row=4, column=0,rowspan=3,columnspan=3,sticky="NSEW") 133 | 134 | b_connect=tk.Button(self,text=" Send",command=lambda: my_server()) 135 | b_connect.grid(row=14,column=0,padx=10,pady=10,sticky="nsew") 136 | 137 | e_data=tk.Entry(self) 138 | e_data.grid(row=14,column=1,padx=10,pady=10,sticky="nsew") 139 | 140 | 141 | def my_server(): 142 | 143 | e_data_v = e_data.get() 144 | e_host_v=e_host.get() 145 | e_port_v=int(e_port.get()) 146 | 147 | 148 | HOST, PORT = e_host_v, e_port_v 149 | data = e_data_v 150 | 151 | # Create a socket (SOCK_STREAM means a TCP socket) 152 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: 153 | # Connect to server and send data 154 | s.connect((HOST, PORT)) 155 | s.sendall(bytes(data + "\n", "utf-8")) 156 | 157 | with open('received_file.png','wb') as f: 158 | print('file opened') 159 | show_1.insert(tk.END,'File Opened !') 160 | show_1.insert(tk.END,'\n') 161 | Q 162 | f.close() 163 | 164 | s.close() 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | app = Page() 174 | app.mainloop() -------------------------------------------------------------------------------- /my_server.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import messagebox 3 | import time 4 | import datetime 5 | from socket import * 6 | import time 7 | from time import ctime 8 | import _thread 9 | 10 | 11 | 12 | 13 | LARGE_FONT= ("Verdana", 12) 14 | 15 | def my_server(show_1,HOST,PORT): 16 | 17 | 18 | BUFSIZE = 1024 19 | ADDR = (HOST, PORT) 20 | 21 | tcpTimeSrvrSock = socket(AF_INET,SOCK_STREAM) 22 | tcpTimeSrvrSock.bind(ADDR) 23 | tcpTimeSrvrSock.listen(5) 24 | currentDT = datetime.datetime.now() 25 | 26 | 27 | while True: 28 | show_1.insert(tk.END,"waiting for connection...") 29 | show_1.insert(tk.END,"\n") 30 | #print ('waiting for connection...') 31 | 32 | tcpTimeClientSock, addr = tcpTimeSrvrSock.accept() 33 | 34 | #print ('...connected from:', addr) 35 | show_1.insert(tk.END,"connected {}".format(addr)) 36 | show_1.insert(tk.END,"\n") 37 | 38 | filename='Tux.png' 39 | f = open(filename,'rb') 40 | l = f.read(1024) 41 | 42 | while (l): 43 | tcpTimeClientSock.send(l) 44 | print('Sent ',repr(l)) 45 | l = f.read(1024) 46 | 47 | f.close() 48 | print('Done sending') 49 | tcpTimeClientSock.send('Thank you for connecting') 50 | tcpTimeClientSock.close() 51 | 52 | 53 | 54 | '''while True: 55 | data = tcpTimeClientSock.recv(BUFSIZE) 56 | if not data: 57 | break 58 | 59 | tcpTimeClientSock.send(bytes(currentDT.strftime("%I:%M:%S %p"),'utf-8')) 60 | 61 | show_1.insert(tk.END,data.decode('utf-8')) 62 | show_1.insert(tk.END,"\n") 63 | print(data.decode('utf-8')) 64 | 65 | tcpTimeClientSock.close() 66 | tcpTimeSrvrSock.close()''' 67 | 68 | class Page(tk.Tk): 69 | 70 | def __init__(self, *args, **kwargs): 71 | 72 | tk.Tk.__init__(self, *args, **kwargs) 73 | container = tk.Frame(self) 74 | 75 | container.pack(side="top", fill="both", expand = True) 76 | 77 | container.grid_rowconfigure(0, weight=1) 78 | container.grid_columnconfigure(0, weight=1) 79 | 80 | self.frames = {} 81 | 82 | for F in (StartPage, PageOne): 83 | 84 | frame = F(container, self) 85 | 86 | self.frames[F] = frame 87 | 88 | frame.grid(row=0, column=0, sticky="nsew") 89 | 90 | self.show_frame(StartPage) 91 | 92 | def show_frame(self, cont): 93 | 94 | frame = self.frames[cont] 95 | frame.tkraise() 96 | 97 | 98 | class StartPage(tk.Frame): 99 | 100 | def __init__(self, parent, controller): 101 | tk.Frame.__init__(self,parent) 102 | 103 | l_title=tk.Label(self, text="Server Software", 104 | font="Arial,12") 105 | l_title.grid(row=0,column=0,columnspan=3, sticky="NSEW",padx=30,pady=30) 106 | 107 | label_username = tk.Label(self, text="Username") 108 | label_password = tk.Label(self, text="Password") 109 | 110 | entry_username = tk.Entry(self,show="*") 111 | 112 | entry_password = tk.Entry(self, show="*") 113 | 114 | label_username.grid(row=2, column=0, sticky='NSEW',padx=10,pady=10) 115 | label_password.grid(row=3, column=0, sticky='NSEW',padx=10,pady=10) 116 | entry_username.grid(row=2, column=1,sticky='NSEW',padx=10,pady=10) 117 | entry_password.grid(row=3, column=1,sticky='NSEW',padx=10,pady=10) 118 | 119 | checkbox = tk.Checkbutton(self, text="Keep me logged in") 120 | checkbox.grid(row=4, column=1,sticky='NSEW',padx=10,pady=10) 121 | 122 | logbtn = tk.Button(self, text="Login", bg="BlACK", fg="White",command=lambda: login_btn_clicked()) 123 | logbtn.grid(row=5, column=1,sticky='NSEW', padx=10, pady=10) 124 | 125 | def login_btn_clicked(): 126 | # print("Clicked") 127 | username = entry_username.get() 128 | password = entry_password.get() 129 | 130 | if len(username) and len(password) > 2: 131 | # print(username, password) 132 | 133 | if username == "admin" and password == "admin": 134 | controller.show_frame(PageOne) 135 | # display a ,essage if username and password is incorrect! 136 | else: 137 | messagebox.showinfo(self,"Invalid username or password ! ") 138 | 139 | else: 140 | messagebox.showinfo(self,"Enter Username and Password") 141 | 142 | 143 | class PageOne(tk.Frame): 144 | 145 | def __init__(self, parent, controller): 146 | tk.Frame.__init__(self, parent) 147 | flag = True 148 | 149 | clock = tk.Label(self, font=('times', 18, 'bold'), bg='green',fg="white") 150 | clock.grid(row=0,column=2, sticky="NSNESWSE",padx=8,pady=8) 151 | 152 | def tick(): 153 | time2=time.strftime('%H:%M:%S') 154 | clock.config(text=time2) 155 | clock.after(200,tick) 156 | tick() 157 | 158 | label = tk.Label(self, text="Server Software ", font="Arial,16",bg="black",fg="White") 159 | label.grid(row=0, column=0, columnspan=2, padx=8, pady=8, sticky="NSNESWSE") 160 | 161 | l_host=tk.Label(self,text="Enter Host NAME") 162 | l_host.grid(row=1, column=0, padx=8, pady=8, sticky="NSNESWSE") 163 | 164 | e_host=tk.Entry(self) 165 | e_host.grid(row=1, column=1, columnspan=2, padx=8, pady=8, sticky="NSNESWSE") 166 | e_host.insert(tk.END,'127.0.0.1') 167 | 168 | 169 | l_port=tk.Label(self,text="Enter Port") 170 | l_port.grid(row=2, column=0, padx=8, pady=8, sticky="NSNESWSE") 171 | 172 | e_port=tk.Entry(self) 173 | e_port.grid(row=2, column=1, columnspan=2, padx=8, pady=8, sticky="NSNESWSE") 174 | e_port.insert(tk.END,12121) 175 | 176 | message_label=tk.Label(self,text="Client Message",font=("Arial,12")) 177 | message_label.grid(row=3,column=0,columnspan=3,padx=10,pady=10,sticky="NSEW") 178 | 179 | 180 | scrollbar_y = tk.Scrollbar(self) 181 | scrollbar_y.grid(row=4, column=3,rowspan=6) 182 | 183 | show_1=tk.Text(self,height=8, width=35, yscrollcommand=scrollbar_y.set, 184 | bg="Grey",fg="White") 185 | show_1.grid(row=4, column=0,rowspan=3,columnspan=3,sticky="NSEW") 186 | 187 | b_connect=tk.Button(self,text=" Connect",command=lambda: connect()) 188 | b_connect.grid(row=14,column=0,padx=10,pady=10,sticky="nsew") 189 | 190 | b_disconnect=tk.Button(self,text=" disconnect",command=lambda: disconnec()) 191 | b_disconnect.grid(row=14,column=1,padx=10,pady=10,sticky="nsew") 192 | 193 | 194 | def runner(): 195 | global after_id 196 | global secs 197 | secs += 1 198 | if secs % 2 == 0: # every other second 199 | e_host_v=e_host.get() 200 | e_port_v=int(e_port.get()) 201 | 202 | #after_id = self.after(1000, runner) # check again in 1 second 203 | 204 | def connect(): 205 | # CONNECT COM PORT 206 | e_host_v=e_host.get() 207 | e_port_v=int(e_port.get()) 208 | _thread.start_new_thread(my_server,(show_1,e_host_v,e_port_v)) 209 | #start_new_thread(my_server,(show_1,e_host_v,e_port_v)) 210 | global secs 211 | secs = 0 212 | #runner() # start repeated checking 213 | 214 | 215 | def disconnec(): 216 | global after_id 217 | if after_id: 218 | self.after_cancel(after_id) 219 | after_id = None 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | app = Page() 228 | app.mainloop() 229 | -------------------------------------------------------------------------------- /received_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soumilshah1995/Transfer_Image_Python_sOCKET_UserInterface/78128924302b958c13230ea4647d736ddbf0665c/received_file.png --------------------------------------------------------------------------------