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
f16c02b3
Commit
f16c02b3
authored
7 years ago
by
emilyconard
Browse files
Options
Downloads
Patches
Plain Diff
No commit message
No commit message
parent
04568344
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
projects/Assignments/homework2/ConardMulticastSender.java
+67
-0
67 additions, 0 deletions
projects/Assignments/homework2/ConardMulticastSender.java
with
67 additions
and
0 deletions
projects/Assignments/homework2/ConardMulticastSender.java
0 → 100644
+
67
−
0
View file @
f16c02b3
import
java.io.ByteArrayOutputStream
;
import
java.io.DataOutputStream
;
import
java.net.DatagramPacket
;
import
java.net.DatagramSocket
;
import
java.net.InetAddress
;
import
java.net.MulticastSocket
;
/**
*
* @author emilyconard
*/
public
class
ConardMulticastSender
{
public
static
final
String
MULTICAST_ADDRESS
=
"239.1.2.15"
;
public
static
final
int
DESTINATION_PORT
=
1717
;
/** How many routers can be crossed */
public
static
final
int
TTL
=
10
;
public
static
void
main
(
String
[]
args
)
{
try
{
int
ID
=
27
;
int
xcord
=
5
;
int
ycord
=
7
;
System
.
setProperty
(
"java.net.preferIPv4Stack"
,
"true"
);
MulticastSocket
multicastSocket
=
new
MulticastSocket
(
1718
);
multicastSocket
.
setTimeToLive
(
TTL
);
InetAddress
multicastAddress
=
InetAddress
.
getByName
(
MULTICAST_ADDRESS
);
System
.
out
.
println
(
multicastAddress
);
// Join group useful on receiving side
multicastSocket
.
joinGroup
(
multicastAddress
);
// You can join multiple groups here
// Put together a message with binary content. "ByteArrayOutputStream"
// is a java.io utility that lets us put together an array of binary
// data, which we put into the UDP packet.
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
DataOutputStream
dos
=
new
DataOutputStream
(
baos
);
dos
.
writeInt
(
ID
);
dos
.
writeInt
(
xcord
);
dos
.
writeInt
(
ycord
);
byte
[]
buffer
=
baos
.
toByteArray
();
DatagramPacket
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
,
multicastAddress
,
DESTINATION_PORT
);
for
(
int
idx
=
0
;
idx
<
100
;
idx
++)
{
multicastSocket
.
send
(
packet
);
Thread
.
sleep
(
1000
);
// Send 100, one per second
System
.
out
.
println
(
"Sent multicast packet "
+
idx
+
" of 100"
);
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
}
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