]> 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 import time
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     elapsed_time=0
18     t=time.time()
19     file_name="lena.jpg"
20     for i in range(10):
21         print(file_name)
22         sbuf.put_utf8(file_name)
23
24         file_size = os.path.getsize(file_name)
25         sbuf.put_utf8(str(file_size))
26
27         with open(file_name, 'rb') as f:
28             sbuf.put_bytes(f.read())
29         print('File Sent')
30     elapsed_time += time.time() - t    
31     print("send lena ",elapsed_time)
32
33     elapsed_time=0
34     t=time.time()
35     file_name="lena2.jpg"
36     for i in range(10):
37         print(file_name)
38         sbuf.put_utf8(file_name)
39
40         file_size = os.path.getsize(file_name)
41         sbuf.put_utf8(str(file_size))
42
43         with open(file_name, 'rb') as f:
44             sbuf.put_bytes(f.read())
45         print('File Sent')
46     elapsed_time += time.time() - t    
47     print("send lena ",elapsed_time)
48
49