]> AND Private Git Repository - Cipher_code.git/commitdiff
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
new
authorRaphaël Couturier <raphael.couturier@univ-fcomte.fr>
Thu, 15 Jul 2021 04:19:46 +0000 (06:19 +0200)
committerRaphaël Couturier <raphael.couturier@univ-fcomte.fr>
Thu, 15 Jul 2021 04:19:46 +0000 (06:19 +0200)
measure_energy_iot/client_tcp4.py
measure_energy_iot/receiver.py [new file with mode: 0644]
measure_energy_iot/sender.py [new file with mode: 0644]

index b163376f731e373028e1e718df283301ff2e67bf..542a7ae3c6dd26e24372e9d06c40cd538b927036 100644 (file)
@@ -75,7 +75,7 @@ for i in range(nb_times):
     im2.save(buf, "JPEG", quality=quality)
     
 elapsed_time += time.time() - t
     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 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    
             sbuf.put_bytes(f.read())
  #       print('File Sent')
     elapsed_time += time.time() - t    
-    print("send scale jpg ",elapsed_time/nb_times)
+    print("send scale jpg ",elapsed_time/nb_times)
 
 
diff --git a/measure_energy_iot/receiver.py b/measure_energy_iot/receiver.py
new file mode 100644 (file)
index 0000000..58d0789
--- /dev/null
@@ -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 (file)
index 0000000..55614e2
--- /dev/null
@@ -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()