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

Private GIT Repository
Merge branch 'master' of ssh://info.iut-bm.univ-fcomte.fr/Cipher_code
[Cipher_code.git] / measure_energy_iot / receiver.py
1 # ----- receiver.py -----
2
3 #!/usr/bin/env python
4
5 from socket import *
6 import sys
7 import select
8 import time
9
10 host="0.0.0.0"
11 port = 9999
12 s = socket(AF_INET,SOCK_DGRAM)
13 s.bind((host,port))
14
15 addr = (host,port)
16 buf=1024
17
18
19 data,addr = s.recvfrom(buf)
20 elapsed_time=0
21 t = time.time()
22 print("Received File:",data.decode().strip())
23 f = open(data.decode().strip()+"2",'wb')
24
25 data,addr = s.recvfrom(buf)
26 try:
27     while(data):
28         f.write(data)
29         s.settimeout(1)
30         data,addr = s.recvfrom(buf)
31 except timeout:
32     s.close()
33     f.close()
34 #    print("File Downloaded")
35 elapsed_time += time.time() - t
36
37 print("receive bmp",elapsed_time)