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
3313ec2e
Commit
3313ec2e
authored
5 years ago
by
jonathanboron
Browse files
Options
Downloads
Patches
Plain Diff
HW4 update 2, sender class more flexible
parent
4f967199
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
assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduSender.java
+60
-52
60 additions, 52 deletions
...hort2019JulySeptember/homework4/Boron/BoronPduSender.java
with
60 additions
and
52 deletions
assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduSender.java
+
60
−
52
View file @
3313ec2e
...
@@ -24,7 +24,6 @@ public class BoronPduSender
...
@@ -24,7 +24,6 @@ public class BoronPduSender
public
static
final
int
DEFAULT_MULTICAST_PORT
=
3000
;
public
static
final
int
DEFAULT_MULTICAST_PORT
=
3000
;
private
int
port
;
private
int
port
;
private
Random
rand
;
InetAddress
multicastAddress
;
InetAddress
multicastAddress
;
public
BoronPduSender
(
int
port
,
String
multicast
)
{
public
BoronPduSender
(
int
port
,
String
multicast
)
{
...
@@ -42,13 +41,56 @@ public class BoronPduSender
...
@@ -42,13 +41,56 @@ public class BoronPduSender
}
}
}
}
public
void
run
()
public
void
run
(
Pdu
aPdu
)
{
{
BoronEntityStatePduCreator
espduCreator
=
new
BoronEntityStatePduCreator
();
rand
=
new
Random
();
System
.
out
.
println
(
"DisExamplesOpenDis7.AllPduSender started..."
);
System
.
out
.
println
(
"DisExamplesOpenDis7.AllPduSender started..."
);
System
.
out
.
println
(
"Generate PDUs and note issues, if any..."
);
System
.
out
.
println
(
"Generate PDUs and note issues, if any..."
);
// Send the PDUs we created
try
{
InetAddress
localMulticastAddress
=
InetAddress
.
getByName
(
DEFAULT_MULTICAST_ADDRESS
);
MulticastSocket
socket
=
new
MulticastSocket
(
DEFAULT_MULTICAST_PORT
);
socket
.
joinGroup
(
localMulticastAddress
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
DataOutputStream
dos
=
new
DataOutputStream
(
baos
);
byte
[]
buffer
;
//Pdu aPdu = generatedPdusList.get(idx);
aPdu
.
marshal
(
dos
);
buffer
=
baos
.
toByteArray
();
DatagramPacket
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
,
localMulticastAddress
,
DEFAULT_MULTICAST_PORT
);
socket
.
send
(
packet
);
try
{
Thread
.
sleep
(
100L
);
}
catch
(
InterruptedException
ex
)
{
}
String
currentPduTypeValuePadded
=
String
.
format
(
"%2s"
,
aPdu
.
getPduType
().
getValue
());
String
currentPduTypePadded
=
String
.
format
(
"%-34s"
,
aPdu
.
getPduType
());
// - indicates right padding of whitespace
System
.
out
.
print
(
"Sent DIS PDU "
+
currentPduTypeValuePadded
+
" "
+
currentPduTypePadded
);
System
.
out
.
println
(
" of type "
+
aPdu
.
getClass
().
getName
());
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
);
}
// write the PDUs out to an XML file.
//PduContainer container = new PduContainer();
//container.setPdus(generatedPdus);
//container.marshallToXml("examplePdus.xml");
}
public
static
void
main
(
String
args
[])
{
BoronEntityStatePduCreator
espduCreator
=
new
BoronEntityStatePduCreator
();
Random
rand
=
new
Random
();
List
<
Pdu
>
generatedPdusList
=
new
ArrayList
<>();
List
<
Pdu
>
generatedPdusList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
3
;
i
++)
for
(
int
i
=
0
;
i
<
3
;
i
++)
...
@@ -77,64 +119,30 @@ public class BoronPduSender
...
@@ -77,64 +119,30 @@ public class BoronPduSender
generatedPdusList
.
add
(
espduCreator
.
newPDU
(
id
,
ForceID
.
FRIENDLY
,
l
,
v
,
o
));
generatedPdusList
.
add
(
espduCreator
.
newPDU
(
id
,
ForceID
.
FRIENDLY
,
l
,
v
,
o
));
}
}
// Send the PDUs we created
System
.
out
.
println
(
"Send the "
+
generatedPdusList
.
size
()
+
" PDUs we created..."
);
System
.
out
.
println
(
"Send the "
+
generatedPdusList
.
size
()
+
" PDUs we created..."
);
try
if
(
args
.
length
==
2
)
{
{
InetAddress
localMulticastAddress
=
InetAddress
.
getByName
(
DEFAULT_MULTICAST_ADDRESS
);
BoronPduSender
sender
=
new
BoronPduSender
(
Integer
.
parseInt
(
args
[
0
]),
args
[
1
]);
MulticastSocket
socket
=
new
MulticastSocket
(
DEFAULT_MULTICAST_PORT
);
for
(
int
i
=
0
;
i
<
generatedPdusList
.
size
();
i
++)
socket
.
joinGroup
(
localMulticastAddress
);
for
(
int
idx
=
0
;
idx
<
generatedPdusList
.
size
();
idx
++)
{
{
Pdu
aPdu
=
generatedPdusList
.
get
(
0
);
Pdu
aPdu
=
generatedPdusList
.
get
(
0
);
sender
.
run
(
aPdu
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
generatedPdusList
.
remove
(
0
);
DataOutputStream
dos
=
new
DataOutputStream
(
baos
);
byte
[]
buffer
;
//Pdu aPdu = generatedPdusList.get(idx);
aPdu
.
marshal
(
dos
);
buffer
=
baos
.
toByteArray
();
DatagramPacket
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
,
localMulticastAddress
,
DEFAULT_MULTICAST_PORT
);
socket
.
send
(
packet
);
try
{
Thread
.
sleep
(
100L
);
}
catch
(
InterruptedException
ex
)
{
}
String
currentPduTypeValuePadded
=
String
.
format
(
"%2s"
,
aPdu
.
getPduType
().
getValue
());
String
currentPduTypePadded
=
String
.
format
(
"%-34s"
,
aPdu
.
getPduType
());
// - indicates right padding of whitespace
System
.
out
.
print
(
"Sent DIS PDU "
+
currentPduTypeValuePadded
+
" "
+
currentPduTypePadded
);
System
.
out
.
println
(
" of type "
+
aPdu
.
getClass
().
getName
());
generatedPdusList
.
remove
(
0
);
}
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
);
}
// write the PDUs out to an XML file.
//PduContainer container = new PduContainer();
//container.setPdus(generatedPdus);
//container.marshallToXml("examplePdus.xml");
}
public
static
void
main
(
String
args
[])
{
if
(
args
.
length
==
2
)
{
BoronPduSender
sender
=
new
BoronPduSender
(
Integer
.
parseInt
(
args
[
0
]),
args
[
1
]);
sender
.
run
();
}
}
else
else
{
{
System
.
out
.
println
(
"Usage: AllPduSender <port> <multicast group>"
);
System
.
out
.
println
(
"Usage: AllPduSender <port> <multicast group>"
);
System
.
out
.
println
(
"Default: AllPduSender "
+
DEFAULT_MULTICAST_PORT
+
" "
+
DEFAULT_MULTICAST_ADDRESS
);
System
.
out
.
println
(
"Default: AllPduSender "
+
DEFAULT_MULTICAST_PORT
+
" "
+
DEFAULT_MULTICAST_ADDRESS
);
BoronPduSender
sender
=
new
BoronPduSender
(
DEFAULT_MULTICAST_PORT
,
DEFAULT_MULTICAST_ADDRESS
);
BoronPduSender
sender
=
new
BoronPduSender
(
DEFAULT_MULTICAST_PORT
,
DEFAULT_MULTICAST_ADDRESS
);
sender
.
run
();
for
(
int
i
=
0
;
i
<
generatedPdusList
.
size
();
i
++)
{
Pdu
aPdu
=
generatedPdusList
.
get
(
0
);
sender
.
run
(
aPdu
);
generatedPdusList
.
remove
(
0
);
}
}
}
System
.
out
.
println
(
"DisExamplesOpenDis7.AllPduSender complete."
);
System
.
out
.
println
(
"DisExamplesOpenDis7.AllPduSender 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