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
75661dad
Commit
75661dad
authored
5 years ago
by
Terry D. Norbraten
Browse files
Options
Downloads
Patches
Plain Diff
don't create objects in a loop
parent
dfcbc1a7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/edu/nps/moves/dis7/examples/EspduReceiver.java
+14
-12
14 additions, 12 deletions
src/edu/nps/moves/dis7/examples/EspduReceiver.java
with
14 additions
and
12 deletions
src/edu/nps/moves/dis7/examples/EspduReceiver.java
+
14
−
12
View file @
75661dad
...
...
@@ -10,6 +10,7 @@ import edu.nps.moves.dis7.EntityStatePdu;
import
edu.nps.moves.dis7.Pdu
;
import
edu.nps.moves.dis7.Vector3Double
;
import
edu.nps.moves.dis7.utilities.PduFactory
;
import
java.io.IOException
;
import
java.net.DatagramPacket
;
import
java.net.MulticastSocket
;
import
java.util.Iterator
;
...
...
@@ -34,8 +35,10 @@ public class EspduReceiver
public
static
void
main
(
String
args
[])
{
MulticastSocket
socket
;
DatagramPacket
packet
;
byte
buffer
[]
=
new
byte
[
MAX_PDU_SIZE
];
DatagramPacket
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
);
PduFactory
pduFactory
=
new
PduFactory
();
List
<
Pdu
>
pduBundle
;
try
{
// Specify the socket to receive data
...
...
@@ -45,25 +48,24 @@ public class EspduReceiver
//InetAddress address = InetAddress.getByName(EspduSender.DEFAULT_MULTICAST_GROUP);
//socket.joinGroup(address);
// Loop infinitely, receiving datagrams
EntityID
eid
;
Vector3Double
position
;
while
(
true
)
{
byte
buffer
[]
=
new
byte
[
MAX_PDU_SIZE
];
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
);
socket
.
receive
(
packet
);
List
<
Pdu
>
pduBundle
=
pduFactory
.
getPdusFromBundle
(
packet
.
getData
(),
packet
.
getLength
());
pduBundle
=
pduFactory
.
getPdusFromBundle
(
packet
.
getData
(),
packet
.
getLength
());
//System.out.println("Bundle size is " + pduBundle.size());
Iterator
it
=
pduBundle
.
iterator
();
Iterator
<
Pdu
>
it
=
pduBundle
.
iterator
();
while
(
it
.
hasNext
())
{
Pdu
aPdu
=
(
Pdu
)
it
.
next
();
Pdu
aPdu
=
it
.
next
();
System
.
out
.
print
(
"got PDU of type: "
+
aPdu
.
getClass
().
getName
());
if
(
aPdu
instanceof
EntityStatePdu
)
{
EntityID
eid
=
((
EntityStatePdu
)
aPdu
).
getEntityID
();
Vector3Double
position
=
((
EntityStatePdu
)
aPdu
).
getEntityLocation
();
eid
=
((
EntityStatePdu
)
aPdu
).
getEntityID
();
position
=
((
EntityStatePdu
)
aPdu
).
getEntityLocation
();
System
.
out
.
print
(
" EID:["
+
eid
.
getSiteID
()
+
", "
+
eid
.
getApplicationID
()
+
", "
+
eid
.
getEntityID
()
+
"] "
);
System
.
out
.
print
(
" Location in DIS coordinates: ["
+
position
.
getX
()
+
", "
+
position
.
getY
()
+
", "
+
position
.
getZ
()
+
"]"
);
}
...
...
@@ -71,8 +73,8 @@ public class EspduReceiver
}
// end trop through PDU bundle
}
// end while
}
// End try
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
catch
(
IO
Exception
e
)
{
System
.
err
.
println
(
e
);
}
}
// end main
}
// end class
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