Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
6f101ab9
Commit
6f101ab9
authored
2 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
variable rename for clarity
parent
1bd1833e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/src/UdpExamples/UnicastUdpSender.java
+7
-7
7 additions, 7 deletions
examples/src/UdpExamples/UnicastUdpSender.java
with
7 additions
and
7 deletions
examples/src/UdpExamples/UnicastUdpSender.java
+
7
−
7
View file @
6f101ab9
...
@@ -45,7 +45,7 @@ public class UnicastUdpSender
...
@@ -45,7 +45,7 @@ public class UnicastUdpSender
DatagramSocket
udpSocket
=
null
;
DatagramSocket
udpSocket
=
null
;
DataOutputStream
dos
=
null
;
DataOutputStream
dos
=
null
;
int
packetID
=
0
;
// counter variable to send in packet
int
packetID
=
0
;
// counter variable to send in packet
float
value
=
-
1.0f
;
// unreachable value is good sentinel to ensure expected changes occur
float
countdown
=
-
1.0f
;
// unreachable value is good sentinel to ensure expected changes occur
String
message
=
MY_NAME
+
" says Hello MV3500"
;
// no really
String
message
=
MY_NAME
+
" says Hello MV3500"
;
// no really
String
padding
=
new
String
();
String
padding
=
new
String
();
...
@@ -85,29 +85,29 @@ public class UnicastUdpSender
...
@@ -85,29 +85,29 @@ public class UnicastUdpSender
for
(
int
index
=
1
;
index
<=
TOTAL_PACKETS_TO_SEND
;
index
++)
// avoid infinite send loops in code, they can be hard to kill!
for
(
int
index
=
1
;
index
<=
TOTAL_PACKETS_TO_SEND
;
index
++)
// avoid infinite send loops in code, they can be hard to kill!
{
{
packetID
++;
// increment counter, prefer using explicit value to index
packetID
++;
// increment counter, prefer using explicit value to index
value
=
TOTAL_PACKETS_TO_SEND
-
packetID
;
// countdown
countdown
=
TOTAL_PACKETS_TO_SEND
-
packetID
;
// countdown
from goal total
boolean
isPacketIdEvenParity
=
((
packetID
%
2
)
==
0
);
// % is modulo operator; result 0 is even parity, 1 is odd parity
boolean
isPacketIdEvenParity
=
((
packetID
%
2
)
==
0
);
// % is modulo operator; result 0 is even parity, 1 is odd parity
// values of interest follow. order and types of what was sent must match what you are reading!
// values of interest follow. order and types of what was sent must match what you are reading!
dos
.
writeInt
(
packetID
);
dos
.
writeInt
(
packetID
);
dos
.
writeFloat
(
value
);
dos
.
writeFloat
(
countdown
);
dos
.
writeUTF
(
message
);
// string value with guaranteed encoding, matches UTF-8 is 8 bit
dos
.
writeUTF
(
message
);
// string value with guaranteed encoding, matches UTF-8 is 8 bit
dos
.
writeBoolean
(
isPacketIdEvenParity
);
dos
.
writeBoolean
(
isPacketIdEvenParity
);
dos
.
flush
();
// sends DataOutputStream to ByteArrayOutputStream
dos
.
flush
();
// sends DataOutputStream to ByteArrayOutputStream
, clearing the buffer
byteArray
=
baos
.
toByteArray
();
// OK so go get the flushed result...
byteArray
=
baos
.
toByteArray
();
// OK so go get the flushed result...
datagramPacket
.
setData
(
byteArray
);
// and put it in the packet...
datagramPacket
.
setData
(
byteArray
);
// and put it in the packet...
udpSocket
.
send
(
datagramPacket
);
// and send it away. boom gone, nonblocking.
udpSocket
.
send
(
datagramPacket
);
// and send it away. boom gone, nonblocking.
// System.out.println("udpSocket output port=" + udpSocket.getLocalPort()); // diagnostic tells what port was chosen by system
// System.out.println("udpSocket output port=" + udpSocket.getLocalPort()); // diagnostic tells what port was chosen by system
if
(
isPacketIdEvenParity
)
if
(
isPacketIdEvenParity
)
padding
=
" "
;
padding
=
" "
;
// single blank character as a string of length 1
else
padding
=
""
;
else
padding
=
""
;
// empty string
Thread
.
sleep
(
100
);
// Send packets at rate of one per second
Thread
.
sleep
(
100
);
// Send packets at rate of one per second
System
.
out
.
println
(
"["
+
UnicastUdpSender
.
class
.
getName
()
+
"] "
+
MY_NAME
+
" "
+
sourceAddress
+
System
.
out
.
println
(
"["
+
UnicastUdpSender
.
class
.
getName
()
+
"] "
+
MY_NAME
+
" "
+
sourceAddress
+
" port="
+
UDP_PORT
+
" port="
+
UDP_PORT
+
" has sent values ("
+
packetID
+
","
+
value
+
",\""
+
message
+
"\","
+
isPacketIdEvenParity
+
" has sent values ("
+
packetID
+
","
+
countdown
+
",\""
+
message
+
"\","
+
isPacketIdEvenParity
+
")"
+
padding
+
" as packet #"
+
index
+
" of "
+
TOTAL_PACKETS_TO_SEND
);
")"
+
padding
+
" as packet #"
+
index
+
" of "
+
TOTAL_PACKETS_TO_SEND
);
baos
.
reset
();
// clear the output stream after sending
baos
.
reset
();
// clear the output stream after sending
}
// end for loop
}
// end for loop
...
...
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