Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python3
- # -*- python -*-
- # -*- coding: utf-8 -*-
- import socket
- import _thread
- fn = '/home/pc/soft/OS/ubuntu-18.04.1-desktop-amd64.iso'
- lock = _thread.allocate_lock()
- def printl(s):
- lock.acquire()
- print(s)
- lock.release()
- def dl(client_socket, addr):
- try:
- printl(f'sending file to {addr}')
- with open(fn, 'rb') as f:
- while True:
- #printl(CHUNK_SIZE) тут оно пишет правильную цифру и вообще все работает как задумано
- data = f.read(CHUNK_SIZE)
- if not data: break
- client_socket.send(data)
- printl(f'complete to {addr}')
- except ConnectionResetError:
- printl(f'aborted to {addr}')
- client_socket.close()
- if __name__ == '__main__':
- CHUNK_SIZE = 128 * 1024
- server_socket = socket.socket()
- server_socket.bind(('', 12345))
- server_socket.listen(5)
- while True:
- client_socket, addr = server_socket.accept()
- _thread.start_new_thread(dl, (client_socket, addr))
- server_socket.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement