From: Raphaƫl Couturier Date: Thu, 15 Jul 2021 04:19:46 +0000 (+0200) Subject: new X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/db082c49480d86a681b6e4d199cafd2ece980293?ds=sidebyside new --- diff --git a/measure_energy_iot/client_tcp4.py b/measure_energy_iot/client_tcp4.py index b163376..542a7ae 100644 --- a/measure_energy_iot/client_tcp4.py +++ b/measure_energy_iot/client_tcp4.py @@ -75,7 +75,7 @@ for i in range(nb_times): im2.save(buf, "JPEG", quality=quality) elapsed_time += time.time() - t -print("compute scale jpg ",elapsed_time/nb_times, " / size of file ",Path('lena3.jpg').stat().st_size) +print("compute scale 4 jpg ",elapsed_time/nb_times, " / size of file ",Path('lena3.jpg').stat().st_size) @@ -132,5 +132,5 @@ with s: sbuf.put_bytes(f.read()) # print('File Sent') elapsed_time += time.time() - t - print("send scale jpg ",elapsed_time/nb_times) + print("send scale 4 jpg ",elapsed_time/nb_times) diff --git a/measure_energy_iot/receiver.py b/measure_energy_iot/receiver.py new file mode 100644 index 0000000..58d0789 --- /dev/null +++ b/measure_energy_iot/receiver.py @@ -0,0 +1,37 @@ +# ----- receiver.py ----- + +#!/usr/bin/env python + +from socket import * +import sys +import select +import time + +host="0.0.0.0" +port = 9999 +s = socket(AF_INET,SOCK_DGRAM) +s.bind((host,port)) + +addr = (host,port) +buf=1024 + + +data,addr = s.recvfrom(buf) +elapsed_time=0 +t = time.time() +print("Received File:",data.decode().strip()) +f = open(data.decode().strip()+"2",'wb') + +data,addr = s.recvfrom(buf) +try: + while(data): + f.write(data) + s.settimeout(2) + data,addr = s.recvfrom(buf) +except timeout: + s.close() + f.close() +# print("File Downloaded") +elapsed_time += time.time() - t + +print("receive bmp",elapsed_time) diff --git a/measure_energy_iot/sender.py b/measure_energy_iot/sender.py new file mode 100644 index 0000000..55614e2 --- /dev/null +++ b/measure_energy_iot/sender.py @@ -0,0 +1,31 @@ +# ----- sender.py ------ + +#!/usr/bin/env python + +from socket import * +import sys +import time + +s = socket(AF_INET,SOCK_DGRAM) +host =sys.argv[1] +port = 9999 +buf =1024 +addr = (host,port) + +file_name=sys.argv[2] +elapsed_time=0 +t = time.time() +s.sendto(file_name.encode(),addr) + +f=open(file_name,"rb") +data = f.read(buf) +while (data): + if(s.sendto(data,addr)): +# print "sending ..." + data = f.read(buf) + +f.close() +elapsed_time += time.time() - t + +print("receive bmp",elapsed_time) +s.close()