]> AND Private Git Repository - Cipher_code.git/blob - measure_energy_iot/client_tcp4.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
new
[Cipher_code.git] / measure_energy_iot / client_tcp4.py
1 import socket
2 import threading
3 import os
4
5 import buffer
6
7 HOST = 'bilbo'
8 PORT = 2345
9
10 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
11 s.connect((HOST, PORT))
12
13 with s:
14     sbuf = buffer.Buffer(s)
15
16
17 #    files = input('Enter file(s) to send: ')
18  #   files_to_send = files.split()
19     file_name="lena.jpg"
20     for i in range(10):
21 #    for file_name in files_to_send:
22         print(file_name)
23         sbuf.put_utf8(file_name)
24
25         file_size = os.path.getsize(file_name)
26         sbuf.put_utf8(str(file_size))
27
28         with open(file_name, 'rb') as f:
29             sbuf.put_bytes(f.read())
30         print('File Sent')
31
32