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
dfcbc1a7
Commit
dfcbc1a7
authored
5 years ago
by
Terry D. Norbraten
Browse files
Options
Downloads
Patches
Plain Diff
don't create objects in a loop
parent
bc6d4ea6
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/EspduReceiverNIO.java
+11
-9
11 additions, 9 deletions
src/edu/nps/moves/dis7/examples/EspduReceiverNIO.java
with
11 additions
and
9 deletions
src/edu/nps/moves/dis7/examples/EspduReceiverNIO.java
+
11
−
9
View file @
dfcbc1a7
...
...
@@ -6,6 +6,7 @@ package edu.nps.moves.dis7.examples;
import
edu.nps.moves.dis7.Pdu
;
import
edu.nps.moves.dis7.utilities.PduFactory
;
import
java.io.IOException
;
import
java.net.DatagramPacket
;
import
java.net.InetAddress
;
import
java.net.MulticastSocket
;
...
...
@@ -30,10 +31,13 @@ public class EspduReceiverNIO
public
static
void
main
(
String
args
[])
{
MulticastSocket
socket
;
DatagramPacket
packet
;
InetAddress
address
;
PduFactory
pduFactory
=
new
PduFactory
();
byte
buffer
[]
=
new
byte
[
MAX_PDU_SIZE
];
DatagramPacket
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
);
ByteBuffer
byteBuffer
;
Pdu
pdu
;
try
{
// Specify the socket to receive data
socket
=
new
MulticastSocket
(
EspduSender
.
DIS_DESTINATION_PORT
);
...
...
@@ -43,22 +47,20 @@ public class EspduReceiverNIO
// Loop infinitely, receiving datagrams
while
(
true
)
{
byte
buffer
[]
=
new
byte
[
MAX_PDU_SIZE
];
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
);
socket
.
receive
(
packet
);
// Uses the NIO byte buffer class--wrap a ByteBuffer instance around
// the data we get from the packet
ByteBuffer
byteBuffer
=
ByteBuffer
.
wrap
(
packet
.
getData
());
Pdu
pdu
=
pduFactory
.
createPdu
(
byteBuffer
);
byteBuffer
=
ByteBuffer
.
wrap
(
packet
.
getData
());
pdu
=
pduFactory
.
createPdu
(
byteBuffer
);
System
.
out
.
println
(
"got PDU of type: "
+
pdu
.
getClass
().
getSimpleName
());
}
// end while
}
// End try
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
catch
(
IO
Exception
e
)
{
System
.
err
.
println
(
e
);
}
}
// end main
...
...
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