Skip to content
Snippets Groups Projects
Commit 731a8cc7 authored by Henrik Tjäder's avatar Henrik Tjäder
Browse files

Fixed the formatting according to PEP8

parent c5c2689d
No related branches found
No related tags found
No related merge requests found
......@@ -12,10 +12,11 @@ NR_OF_PACKETS=10 #TOTAL NR. OF PACKETS TO SEND
PACKETS_PER_SEC = 100 # PACKETS PER SECOND
# CLIENT - RECEIVER
UDP_RECEIVE_IP = '::1' #IP ADDRESS TO LISTEN FOR INCOMMING PACKETS (v4 or v6)
UDP_RECEIVE_PORT=55555 #IP PORT TO LISTEN FOR INCOMMING PACKETS
UDP_RECEIVE_IP = '::1' # LISTENING IP ADDRESS (v4 or v6)
UDP_RECEIVE_PORT = 55555 # IP PORT TO LISTEN FOR INCOMING PACKETS
BUFFER = 4096
#CLIENT-RECEIVER PART
def udp_client_receive(UDP_RECEIVE_IP, UDP_RECEIVE_PORT):
ADDR = (UDP_RECEIVE_IP, UDP_RECEIVE_PORT)
......@@ -50,8 +51,14 @@ def udp_client_receive(UDP_RECEIVE_IP, UDP_RECEIVE_PORT):
packet_number = str(splitdata[1].strip("' '"))
packet_number = packet_number.lstrip('0')
#WRITE TO FILE AND DO PACKET COUNT
outfile = open("udp_twoway_results.csv", "a").write(str(time.ctime()+','+'received , '+ packet_number+' , '+str(rt_delay)+'\n'))
print (time.ctime()+','+'received , '+ packet_number+' , '+str(rt_delay))
#outfile = open("udp_twoway_results.csv", "a").\
open("udp_twoway_results.csv", "a").\
write(str(time.ctime() + ',' + 'received , ' +
packet_number + ' , ' + str(rt_delay) + '\n'))
print (time.ctime() + ',' + 'received , ' +
packet_number + ' , ' + str(rt_delay))
# Store minimum and maximum delay
if rt_delay > max_delay:
max_delay = rt_delay
......@@ -62,8 +69,10 @@ def udp_client_receive(UDP_RECEIVE_IP, UDP_RECEIVE_PORT):
packet_count_rcvd = packet_count_rcvd + 1
cumulative_delay = cumulative_delay + rt_delay
#CLIENT SERVER SIDE
def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT, PACKET_SIZE, NR_OF_PACKETS, PACKETS_PER_SEC):
def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT,
PACKET_SIZE, NR_OF_PACKETS, PACKETS_PER_SEC):
inter_departure_time = 1. / PACKETS_PER_SEC
packet_count_snd = 0
......@@ -79,10 +88,11 @@ def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT, PACKET_SIZE, NR_OF_PACKETS, P
padding = ''
for j in range(98, PACKET_SIZE):
padding = padding + str(1)
for i in range (1,NR_OF_PACKETS+1): #SEND SPECIFIED NUMBER OF PACKETS
for i in range(1, NR_OF_PACKETS + 1): # SEND SPECIFIED NR OF PKTS
time.sleep(inter_departure_time)
snd_sock6 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
snd_sock6.sendto(str(("%.5f" % time.time(),str('%08d' % i), padding)), (UDP_DEST_IP, UDP_DEST_PORT) )
snd_sock6.sendto(str(("%.5f" % time.time(), str('%08d' % i),
padding)), (UDP_DEST_IP, UDP_DEST_PORT))
packet_count_snd = packet_count_snd + 1
#IF NOT IPv6
......@@ -94,7 +104,8 @@ def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT, PACKET_SIZE, NR_OF_PACKETS, P
for i in range(1, NR_OF_PACKETS + 1):
time.sleep(inter_departure_time)
snd_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
snd_sock.sendto(str(("%.5f" % time.time(),str('%08d' % i), padding)), (UDP_DEST_IP, UDP_DEST_PORT) )
snd_sock.sendto(str(("%.5f" % time.time(), str('%08d' % i),
padding)), (UDP_DEST_IP, UDP_DEST_PORT))
packet_count_snd = packet_count_snd + 1
#WAIT 5SEC FOR ALL PACKETS TO ARRIVE
......@@ -114,8 +125,12 @@ def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT, PACKET_SIZE, NR_OF_PACKETS, P
#START THE THREADS FOR SENDER AND RECEIVER
if __name__ == "__main__":
receiver_thread = Thread(target=udp_client_receive, args=(UDP_RECEIVE_IP, UDP_RECEIVE_PORT))
receiver_thread = Thread(target=udp_client_receive,
args=(UDP_RECEIVE_IP, UDP_RECEIVE_PORT))
receiver_thread.daemon = True
receiver_thread.start()
time.sleep(1)
sender_thread = Thread(target=udp_client_send, args=(UDP_DEST_IP, UDP_DEST_PORT, PACKET_SIZE, NR_OF_PACKETS, PACKETS_PER_SEC)).start()
sender_thread = Thread(target=udp_client_send,
args=(UDP_DEST_IP, UDP_DEST_PORT,
PACKET_SIZE, NR_OF_PACKETS,
PACKETS_PER_SEC)).start()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment