From db082c49480d86a681b6e4d199cafd2ece980293 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Couturier?= Date: Thu, 15 Jul 2021 06:19:46 +0200 Subject: [PATCH 1/1] new --- measure_energy_iot/client_tcp4.py | 4 ++-- measure_energy_iot/receiver.py | 37 +++++++++++++++++++++++++++++++ measure_energy_iot/sender.py | 31 ++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 measure_energy_iot/receiver.py create mode 100644 measure_energy_iot/sender.py 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() -- 2.39.5