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
f5e33363
Commit
f5e33363
authored
5 years ago
by
J. M. Bailey
Browse files
Options
Downloads
Patches
Plain Diff
New dis 7 api
parent
81c70251
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/OpenDis7Examples/PduReceiver.java
+63
-68
63 additions, 68 deletions
examples/src/OpenDis7Examples/PduReceiver.java
with
63 additions
and
68 deletions
examples/src/OpenDis7Examples/PduReceiver.java
+
63
−
68
View file @
f5e33363
...
...
@@ -7,75 +7,70 @@ import edu.nps.moves.dis7.*;
import
edu.nps.moves.dis7.enumerations.*
;
import
edu.nps.moves.dis7.util.*
;
public
class
PduReceiver
public
class
PduReceiver
{
public
static
final
int
DEFAULT_MULTICAST_PORT
=
PduSender
.
DEFAULT_MULTICAST_PORT
;
public
static
final
String
DEFAULT_MULTICAST_ADDRESS
=
PduSender
.
DEFAULT_MULTICAST_ADDRESS
;
public
static
final
boolean
USE_FAST_ESPDU
=
false
;
public
static
void
main
(
String
args
[])
{
PduFactory
factory
;
MulticastSocket
socket
;
InetAddress
address
;
DatagramPacket
packet
;
try
{
System
.
out
.
println
(
"DisExamplesOpenDis7.PduReceiver started..."
);
if
(
args
.
length
==
2
)
{
socket
=
new
MulticastSocket
(
Integer
.
parseInt
(
args
[
0
]));
address
=
InetAddress
.
getByName
(
args
[
1
]);
}
else
{
System
.
out
.
println
(
"Usage: PduReceiver <port> <multicast group>"
);
System
.
out
.
println
(
"Default: PduReceiver "
+
DEFAULT_MULTICAST_PORT
+
" "
+
DEFAULT_MULTICAST_ADDRESS
);
socket
=
new
MulticastSocket
(
DEFAULT_MULTICAST_PORT
);
address
=
InetAddress
.
getByName
(
DEFAULT_MULTICAST_ADDRESS
);
}
socket
.
joinGroup
(
address
);
factory
=
new
PduFactory
();
while
(
true
)
// Loop infinitely, receiving datagrams
{
byte
buffer
[]
=
new
byte
[
1500
];
// typical MTU size
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
);
// reset
socket
.
receive
(
packet
);
Pdu
pdu
=
factory
.
createPdu
(
packet
.
getData
());
if
(
pdu
!=
null
)
{
short
currentPduType
=
pdu
.
getPduType
();
String
currentPduTypeName
=
pdu
.
getClass
().
getName
();
short
currentProtocolFamilyID
=
pdu
.
getProtocolFamily
();
String
currentPduFamilyName
=
pdu
.
getClass
().
getSuperclass
().
getSimpleName
();
StringBuilder
message
=
new
StringBuilder
();
message
.
append
(
"received DIS PDU: "
);
message
.
append
(
"pduType "
);
if
(
currentPduType
<
10
)
message
.
append
(
" "
);
message
.
append
(
currentPduType
).
append
(
" "
).
append
(
currentPduTypeName
);
message
.
append
(
", protocolFamily "
).
append
(
currentProtocolFamilyID
);
message
.
append
(
" "
).
append
(
currentPduFamilyName
);
System
.
out
.
println
(
message
.
toString
());
}
else
System
.
out
.
println
(
"received packet but pdu is null, packet.getData().length="
+
packet
.
getData
().
length
+
", error..."
);
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Problem with DisExamplesOpenDis7.PduReceiver, see exception trace:"
);
System
.
out
.
println
(
e
);
}
finally
{
System
.
out
.
println
(
"DisExamplesOpenDis7.PduReceiver complete."
);
public
static
final
int
DEFAULT_MULTICAST_PORT
=
PduSender
.
DEFAULT_MULTICAST_PORT
;
public
static
final
String
DEFAULT_MULTICAST_ADDRESS
=
PduSender
.
DEFAULT_MULTICAST_ADDRESS
;
public
static
final
boolean
USE_FAST_ESPDU
=
false
;
public
static
void
main
(
String
args
[])
{
PduFactory
factory
;
MulticastSocket
socket
;
InetAddress
address
;
DatagramPacket
packet
;
try
{
System
.
out
.
println
(
"DisExamplesOpenDis7.PduReceiver started..."
);
if
(
args
.
length
==
2
)
{
socket
=
new
MulticastSocket
(
Integer
.
parseInt
(
args
[
0
]));
address
=
InetAddress
.
getByName
(
args
[
1
]);
}
else
{
System
.
out
.
println
(
"Usage: PduReceiver <port> <multicast group>"
);
System
.
out
.
println
(
"Default: PduReceiver "
+
DEFAULT_MULTICAST_PORT
+
" "
+
DEFAULT_MULTICAST_ADDRESS
);
socket
=
new
MulticastSocket
(
DEFAULT_MULTICAST_PORT
);
address
=
InetAddress
.
getByName
(
DEFAULT_MULTICAST_ADDRESS
);
}
socket
.
joinGroup
(
address
);
factory
=
new
PduFactory
();
while
(
true
)
// Loop infinitely, receiving datagrams
{
byte
buffer
[]
=
new
byte
[
1500
];
// typical MTU size
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
);
// reset
socket
.
receive
(
packet
);
Pdu
pdu
=
factory
.
createPdu
(
packet
.
getData
());
if
(
pdu
!=
null
)
{
DISPDUType
currentPduType
=
pdu
.
getPduType
();
//short currentPduType = pdu.getPduType();
String
currentPduTypeName
=
pdu
.
getClass
().
getName
();
DISProtocolFamily
currentProtocolFamilyID
=
pdu
.
getProtocolFamily
();
//short currentProtocolFamilyID = pdu.getProtocolFamily();
String
currentPduFamilyName
=
pdu
.
getClass
().
getSuperclass
().
getSimpleName
();
StringBuilder
message
=
new
StringBuilder
();
message
.
append
(
"received DIS PDU: "
);
message
.
append
(
"pduType "
);
if
(
currentPduType
.
getValue
()
<
10
)
message
.
append
(
" "
);
message
.
append
(
currentPduType
).
append
(
" "
).
append
(
currentPduTypeName
);
message
.
append
(
", protocolFamily "
).
append
(
currentProtocolFamilyID
);
message
.
append
(
" "
).
append
(
currentPduFamilyName
);
System
.
out
.
println
(
message
.
toString
());
}
else
System
.
out
.
println
(
"received packet but pdu is null, packet.getData().length="
+
packet
.
getData
().
length
+
", error..."
);
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Problem with DisExamplesOpenDis7.PduReceiver, see exception trace:"
);
System
.
out
.
println
(
e
);
}
finally
{
System
.
out
.
println
(
"DisExamplesOpenDis7.PduReceiver complete."
);
}
}
}
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