Skip to main content
Sign in
Snippets Groups Projects
Commit 977e7cb7 authored by Henrik Tjäder's avatar Henrik Tjäder
Browse files

Endless execution with proper thread handling

parent 9372898a
No related branches found
No related tags found
No related merge requests found
import socket
import time
import sys
from threading import Thread
import threading
from threading import Thread, Timer
import numpy as np
from array import *
......@@ -66,8 +67,10 @@ def udp_client_receive(UDP_RECEIVE_IP, UDP_RECEIVE_PORT):
rt_delay_array.append(rt_delay)
print((time.ctime() + ',' + 'received , ' +
packet_number + ' , ' + str(rt_delay)))
# Comment this line to disable per packet print
#print((time.ctime() + ',' + 'received , ' +
#packet_number + ' , ' + str(rt_delay)))
# Store minimum and maximum delay
if rt_delay > max_delay:
......@@ -127,7 +130,8 @@ def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT,
PLR = 100 - ((packet_count_rcvd * 100.) / packet_count_snd)
print('\n', packet_count_snd, 'packets sent')
print('\n')
print(packet_count_snd, 'packets sent')
print(packet_count_rcvd, 'packets received')
print('packet loss ratio = ', round(PLR, 3), '%')
......@@ -147,8 +151,10 @@ def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT,
else:
avg_packet_delay = cumulative_delay / packet_count_rcvd
#CALCULATE STABILITY
network_stability = int(((packet_count_rcvd/packet_count_snd)*(avg_packet_delay/packet_wait_time)*100)+0.5)
network_stability = int(((packet_count_rcvd / packet_count_snd)\
* (avg_packet_delay / packet_wait_time) * 100) + 0.5)
print('avg.rtt = ', avg_packet_delay)
print('stability = ', network_stability)
#START THE THREADS FOR SENDER AND RECEIVER
......@@ -158,7 +164,17 @@ if __name__ == "__main__":
receiver_thread.daemon = True
receiver_thread.start()
time.sleep(1)
while threading.activeCount() <= 2:
# Set the count of the received packets to 0,
# since the listener thread runs continously
packet_count_rcvd = 0
packet_count_snd = 0
sender_thread = Thread(target=udp_client_send,
args=(UDP_DEST_IP, UDP_DEST_PORT,
PACKET_SIZE, NR_OF_PACKETS,
PACKETS_PER_SEC)).start()
PACKETS_PER_SEC))
sender_thread.start()
while sender_thread.is_alive():
time.sleep(1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment