import socket import threading from tkinter import * import pyautogui import os BUFSIZE = 2048 PORT = 5050 SERVER = "127.0.0.1" ADDR = (SERVER, PORT) FORMAT = 'utf-8' DISCONNECT_MESSAGE = "!DISCONNECT" def takeScreenShot(): myscreenshot = pyautogui.screenshot() #save_path = tk.filedialog.asksaveasfilename() myscreenshot.save("pic1.jpg") filetosend = open("pic1.jpg", "rb") data = filetosend.read(1024) while data: s.send(data) data = filetosend.read(1024) filetosend.close() #"Send DONE." s.send(b"DONE") #to break while print("Done Sending.") os.remove("pic1.jpg") #delete picture in sever s.shutdown(2) s.close() def handle_client(connection,client_addr): while True: data = connection.recv(BUFSIZ) cmd = data.decode("utf-8") if cmd == "takepicture": while case_takepic: data = client.recv(BUFSIZ) cmd_takepic = data.decode("utf-8") if cmd_takepic == "takepic": def start(): server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(ADDR) server.listen() connection, client_addr = server.accept() thread = threading.Thread(target=handle_client, args=(connection, client_addr)) thread.start() msg="Connected!!" connection.send(bytes(msg, "utf-8")) # while True: #do sth window=Tk() btn=Button(window, text="Server Open", fg='black',width=20,height=10,command=start) btn.place(x=20, y=10) window.title('Server') window.geometry("200x200") window.mainloop() server.close()