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
2cdf2959
Commit
2cdf2959
authored
5 years ago
by
brutzman
Browse files
Options
Downloads
Patches
Plain Diff
better sentinel and looping control
parent
a202106a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/src/UdpMulticastHttpExamples/MulticastReceiver.java
+3
-3
3 additions, 3 deletions
examples/src/UdpMulticastHttpExamples/MulticastReceiver.java
examples/src/UdpMulticastHttpExamples/MulticastSender.java
+8
-2
8 additions, 2 deletions
examples/src/UdpMulticastHttpExamples/MulticastSender.java
with
11 additions
and
5 deletions
examples/src/UdpMulticastHttpExamples/MulticastReceiver.java
+
3
−
3
View file @
2cdf2959
...
...
@@ -20,7 +20,7 @@ public class MulticastReceiver {
/** Time to live: how many router-decrement levels can be crossed */
public
static
final
int
TTL
=
10
;
final
private
static
boolean
infiniteReadLoop
=
tru
e
;
final
private
static
boolean
infiniteReadLoop
=
fals
e
;
public
static
void
main
(
String
[]
args
)
{
...
...
@@ -63,9 +63,9 @@ public class MulticastReceiver {
nextChar
=
dis
.
readChar
();
firstCharacters
+=
nextChar
;
}
if
(
firstCharacters
.
equals
(
"quit;"
))
if
(
firstCharacters
.
contains
(
MulticastSender
.
QUIT_SENTINEL
))
{
System
.
out
.
println
(
"Received
\"quit;\" sentinel
"
);
System
.
out
.
println
(
"Received
sentinel \""
+
MulticastSender
.
QUIT_SENTINEL
+
"\"
"
);
if
(!
infiniteReadLoop
)
break
;
// exit out of reading loop
}
...
...
This diff is collapsed.
Click to expand it.
examples/src/UdpMulticastHttpExamples/MulticastSender.java
+
8
−
2
View file @
2cdf2959
...
...
@@ -13,10 +13,16 @@ import java.net.*;
*/
public
class
MulticastSender
{
// reserved range for all IPv4 multicast: 224.0.0.0 through 239.255.255.255
// https://en.wikipedia.org/wiki/Multicast_address
// https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml
public
static
final
String
MULTICAST_ADDRESS
=
"239.1.2.15"
;
// within reserved multicast address range
public
static
final
int
DESTINATION_PORT
=
1718
;
/** Time to live: how many router-decrement levels can be crossed */
public
static
final
int
TTL
=
10
;
public
static
final
int
TTL
=
10
;
public
static
final
String
QUIT_SENTINEL
=
"QUIT QUIT QUIT!"
;
@SuppressWarnings
(
"SleepWhileInLoop"
)
public
static
void
main
(
String
[]
args
)
...
...
@@ -60,7 +66,7 @@ public class MulticastSender {
dos
.
writeFloat
(
17.0f
);
// arbitrary data, needs Java or byte-alignment to read
dos
.
writeFloat
(
23.0f
);
// arbitrary data, needs Java or byte-alignment to read
}
else
dos
.
writeChars
(
"quit
;"
);
// note string must include ; semicolon as termination sentinel
else
dos
.
writeChars
(
QUIT_SENTINEL
+
"
;"
);
// note string must include ; semicolon as termination sentinel
byte
[]
buffer
=
baos
.
toByteArray
();
DatagramPacket
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
,
multicastAddress
,
DESTINATION_PORT
);
...
...
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