import socket import shutil import os import tkinter as tk from tkinter.filedialog import asksaveasfilename IP = "127.0.0.1" PORT = 5050 BUFSIZ = 2048 client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_addr = (IP, PORT) client.connect(client_addr) def receivePicture(): filetodown = open("pic1.jpg", "wb") while True: data = client.recv(1024) if not data: break filetodown.write(data) filetodown.close() def savePicPath(): # day la luu file vo tep save_path = asksaveasfilename() shutil.copyfile("pic1.jpg",save_path) def sendtoServer(): msg = "takepic" client.send(bytes(msg, "utf-8")) case_takepic = True while case_takepic: if msg == "takepic": receivePicture() print("Enter new cmd:") msg = input("Client:") if msg == "savepic": savePicPath() elif msg == "takepic": client.send(bytes(msg, "utf-8")) elif msg == "quit": break elif msg == "savepic": savePicPath() elif msg == "quit": break sendtoServer() os.remove("pic1.jpg") #delete picture in source file client.shutdown(2) client.close() #Done :)