Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
D0020E-projekt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Henrik Tjäder
D0020E-projekt
Commits
5c6f0b20
Commit
5c6f0b20
authored
10 years ago
by
Henrik Tjäder
Browse files
Options
Downloads
Patches
Plain Diff
Calculate range and std.dev. close files
parent
e2754426
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
UDP-client-server.py
+18
-3
18 additions, 3 deletions
UDP-client-server.py
with
18 additions
and
3 deletions
UDP-client-server.py
+
18
−
3
View file @
5c6f0b20
...
...
@@ -2,6 +2,8 @@ import socket
import
time
import
sys
from
threading
import
Thread
import
numpy
as
np
from
array
import
*
#DEFINE INPUTS HERE
#CLIENT - SENDER
...
...
@@ -31,8 +33,10 @@ def udp_client_receive(UDP_RECEIVE_IP, UDP_RECEIVE_PORT):
global
cumulative_delay
global
min_delay
global
max_delay
global
rt_delay_array
min_delay
=
100.
max_delay
=
0.
rt_delay_array
=
array
(
'
f
'
)
packet_count_rcvd
=
0
cumulative_delay
=
0.
...
...
@@ -51,11 +55,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").\
open
(
"
udp_twoway_results.csv
"
,
"
a
"
).
\
outfile
=
open
(
"
udp_twoway_results.csv
"
,
"
a
"
).
\
write
(
str
(
time
.
ctime
()
+
'
,
'
+
'
received ,
'
+
packet_number
+
'
,
'
+
str
(
rt_delay
)
+
'
\n
'
))
# Store all rt_delay for std.dev. calculation
rt_delay_array
.
append
(
rt_delay
)
print
(
time
.
ctime
()
+
'
,
'
+
'
received ,
'
+
packet_number
+
'
,
'
+
str
(
rt_delay
))
...
...
@@ -64,11 +71,12 @@ def udp_client_receive(UDP_RECEIVE_IP, UDP_RECEIVE_PORT):
max_delay
=
rt_delay
if
rt_delay
<
min_delay
:
min_delay
=
rt_delay
print
(
max_delay
,
min_delay
)
packet_count_rcvd
=
packet_count_rcvd
+
1
cumulative_delay
=
cumulative_delay
+
rt_delay
outfile
.
close
()
#CLIENT SERVER SIDE
def
udp_client_send
(
UDP_DEST_IP
,
UDP_DEST_PORT
,
...
...
@@ -112,12 +120,19 @@ def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT,
time
.
sleep
(
5
)
# Perhaps create a custom object where we store the statistics?
# Or from here save it directly into the database?
PLR
=
100
-
((
packet_count_rcvd
*
100.
)
/
packet_count_snd
)
print
'
\n
'
,
packet_count_snd
,
'
packets sent
'
print
packet_count_rcvd
,
'
packets received
'
print
'
packet loss ratio =
'
,
round
(
PLR
,
3
),
'
%
'
print
'
range =
'
,
(
max_delay
-
min_delay
)
#CALCULATE THE STANDARD DEVIATION
print
'
std. dev.:
'
,
np
.
std
(
rt_delay_array
)
if
packet_count_rcvd
==
0
:
pass
else
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment