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
30acbbbe
Commit
30acbbbe
authored
5 years ago
by
J. M. Bailey
Browse files
Options
Downloads
Patches
Plain Diff
Add example to show use of DisThreadedNetIF
parent
8a708230
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/ThreadedNetExample.java
+56
-0
56 additions, 0 deletions
src/edu/nps/moves/dis7/examples/ThreadedNetExample.java
with
56 additions
and
0 deletions
src/edu/nps/moves/dis7/examples/ThreadedNetExample.java
0 → 100644
+
56
−
0
View file @
30acbbbe
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package
edu.nps.moves.dis7.examples
;
import
edu.nps.moves.dis7.Pdu
;
import
edu.nps.moves.dis7.enumerations.Country
;
import
edu.nps.moves.dis7.util.DisThreadedNetIF
;
import
edu.nps.moves.dis7.util.PduFactory
;
/**
* ThreadedNetExample.java created on Sep 9, 2019
* MOVES Institute Naval Postgraduate School, Monterey, CA, USA www.nps.edu
*
* Shows how to use DisThreadedNetIF from an application class
*
* @author Mike Bailey, jmbailey@nps.edu
* @version $Id$
*/
public
class
ThreadedNetExample
{
public
static
void
main
(
String
[]
args
)
{
// Create an instance of DisThreadedNetIF using default port 3000, mcast 225.4.5.6, use other constructor to specific port and ip
DisThreadedNetIF
netif
=
new
DisThreadedNetIF
();
// Internally, the DisThreadeNetIF class has constructed whatever threads it needs to operated
// We want to listen also, so add a listener, using JDK8+ lambda grammar
netif
.
addListener
(
pdu
->
handleReceivedPdu
(
pdu
));
// Use PduFactory to make pdus, default country = Deutschland, exercise, site, app, absolute timestamps
PduFactory
factory
=
new
PduFactory
(
Country
.
GERMANY_DEU
,
(
byte
)
1
,
(
short
)
2
,
(
short
)
3
,
true
);
// Make and send 3 pdus with no delay between, testing threaded receiver performance
netif
.
send
(
factory
.
makeEntityStatePdu
());
System
.
out
.
println
(
"Sent EntityStatePdu"
);
netif
.
send
(
factory
.
makeFirePdu
());
System
.
out
.
println
(
"Sent FirePdu"
);
netif
.
send
(
factory
.
makeCollisionPdu
());
System
.
out
.
println
(
"Sent CollisionPdu"
);
// Wait a bit to see output
try
{
Thread
.
sleep
(
2000L
);}
catch
(
InterruptedException
ex
){}
System
.
out
.
println
(
"End of example"
);
}
private
static
void
handleReceivedPdu
(
Pdu
pdu
)
{
// Do something here with the pdu you received
System
.
out
.
println
(
"Received "
+
pdu
.
getClass
().
getSimpleName
());
}
}
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