pyinstaller.exe --onefile --windowed --icon=124.ico test.py
import socket
import argparse
import sys
import time
HOST = '127.0.0.1'
PORT = 9001
BUFFER_SIZE = 1024
TOTAL_CLIENTS = 10
def main(arg):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((arg.host, arg.port))
sock.listen(TOTAL_CLIENTS)
while True:
conn, address = sock.accept()
print(f'Connect from address - {address}')
try:
chunk = conn.recv(BUFFER_SIZE)
if not chunk:
continue
print('Receive')
filename = f'file_{int(time.time())}.png'
print(filename)
f = open(filename, 'wb')
while chunk:
if not chunk:
break
f.write(chunk)
chunk = conn.recv(BUFFER_SIZE)
f.close()
print(f'copied the file - {filename}')
except Exception as Error:
print(Error)
finally:
conn.close()
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(description='test')
arg_parser.add_argument("-s", dest="host", default=HOST)
arg_parser.add_argument("-p", dest="port", default=PORT)
args = arg_parser.parse_args()
try:
main(args)
except KeyboardInterrupt:
print('EXIT')
sys.exit()
import os.path
import socket
import argparse
import sys
import time
HOST = '127.0.0.1'
PORT = 9001
BUFFER_SIZE = 1024
TOTAL_CLIENTS = 10
def main(arg):
while True:
file = input("Введите путь к файлу: ")
print(file)
if not os.path.exists(file):
print("File not found")
continue
filename = os.path.basename(file)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((arg.host, arg.port))
try:
fi = open(file, "rb")
data = fi.read(BUFFER_SIZE)
if not data:
break
while data:
sock.send(data)
data = fi.read(BUFFER_SIZE)
fi.close()
print(f'file - {filename} send')
except IOError as Error:
print(f'Error - {Error} while sending file - {filename}')
finally:
sock.close()
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("-s", dest="host", default=HOST)
arg_parser.add_argument("-p", dest="port", default=PORT)
args = arg_parser.parse_args()
try:
main(args)
except KeyboardInterrupt:
print('EXIT')
sys.exit()
python "D:\PyProjects\Test\Literal2.py"