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
d6f6f046
Commit
d6f6f046
authored
4 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
multiple cleanups, add ability to set address/port
parent
248347ba
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
src/edu/nps/moves/dis7/utilities/DisThreadedNetworkInterface.java
+32
-24
32 additions, 24 deletions
...nps/moves/dis7/utilities/DisThreadedNetworkInterface.java
with
32 additions
and
24 deletions
src/edu/nps/moves/dis7/utilities/DisThreadedNetworkInterface.java
+
32
−
24
View file @
d6f6f046
...
@@ -26,6 +26,9 @@ import java.util.logging.Logger;
...
@@ -26,6 +26,9 @@ import java.util.logging.Logger;
*/
*/
public
class
DisThreadedNetworkInterface
public
class
DisThreadedNetworkInterface
{
{
public
static
String
DEFAULT_MULTICAST_ADDRESS
=
"225.4.5.6"
;
public
static
int
DEFAULT_DIS_PORT
=
3000
;
private
static
final
String
TRACE_PREFIX
=
"["
+
DisThreadedNetworkInterface
.
class
.
getName
()
+
"] "
;
private
static
final
String
TRACE_PREFIX
=
"["
+
DisThreadedNetworkInterface
.
class
.
getName
()
+
"] "
;
private
boolean
verbose
=
true
;
private
boolean
verbose
=
true
;
...
@@ -63,48 +66,45 @@ public class DisThreadedNetworkInterface
...
@@ -63,48 +66,45 @@ public class DisThreadedNetworkInterface
/************ Begin class ***************/
/************ Begin class ***************/
public
static
int
DEFAULT_DIS_PORT
=
3000
;
/** MTU 8192: TODO this has actually been superseded by a larger buffer size, but good enough for now */
public
static
String
DEFAULT_MULTICAST_ADDRESS
=
"225.4.5.6"
;
/** 8192: This has actually been superseded by a larger buffer size, but good enough for now */
public
static
final
int
MAX_DIS_PDU_SIZE
=
8192
;
public
static
final
int
MAX_DIS_PDU_SIZE
=
8192
;
/** 1500: size of an
e
thernet frame, common value to avoid packet segmentation */
/**
MTU
1500: size of an
E
thernet frame, common value to avoid packet segmentation */
public
static
final
int
MAX_TRANSMISSION_UNIT_SIZE
=
1500
;
public
static
final
int
MAX_TRANSMISSION_UNIT_SIZE
=
1500
;
private
int
disPort
;
private
int
disPort
;
private
String
mcastGroup
;
private
String
multicastAddress
;
private
boolean
killed
=
false
;
private
boolean
killed
=
false
;
private
InetAddress
maddr
;
private
InetAddress
inetAddress
;
private
InetSocketAddress
group
;
private
InetSocketAddress
inetSocket
;
private
NetworkInterface
ni
;
private
NetworkInterface
networkInterface
;
private
DatagramSocket
socket
=
null
;
private
DatagramSocket
socket
=
null
;
/**
/**
* Default constructor using default port 3000 and multicast address 225.4.5.6
* Default constructor using default port 3000 and multicast address 225.4.5.6
*/
*/
public
DisThreadedNetworkInterface
()
public
DisThreadedNetworkInterface
()
{
{
this
(
DEFAULT_
DIS_PORT
,
DEFAULT_MULTICAST_ADDRESS
);
this
(
DEFAULT_
MULTICAST_ADDRESS
,
DEFAULT_DIS_PORT
);
}
}
/**
/**
*
* Constructor
* @param multicastGroup the multicast group address to utilize
* @param port the multicast port to utilize
* @param port the multicast port to utilize
* @param mcastgroup the multicast group address to utilize
*/
*/
public
DisThreadedNetworkInterface
(
int
port
,
String
mcast
g
roup
)
public
DisThreadedNetworkInterface
(
String
m
ulti
cast
G
roup
,
int
port
)
{
{
disPort
=
port
;
disPort
=
port
;
m
castGroup
=
m
cast
g
roup
;
m
ulticastAddress
=
multi
cast
G
roup
;
try
{
try
{
maddr
=
InetAddress
.
getByName
(
m
castGroup
);
inetAddress
=
InetAddress
.
getByName
(
m
ulticastAddress
);
}
catch
(
UnknownHostException
ex
)
{
}
catch
(
UnknownHostException
ex
)
{
Logger
.
getLogger
(
DisThreadedNetworkInterface
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
DisThreadedNetworkInterface
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
group
=
new
InetSocketAddress
(
maddr
,
d
isPort
);
inetSocket
=
new
InetSocketAddress
(
inetAddress
,
getD
isPort
()
);
n
i
=
findIpv4Interface
();
n
etworkInterface
=
findIpv4Interface
();
init
();
init
();
}
}
...
@@ -182,7 +182,7 @@ public class DisThreadedNetworkInterface
...
@@ -182,7 +182,7 @@ public class DisThreadedNetworkInterface
public
String
getMcastGroup
()
public
String
getMcastGroup
()
{
{
return
m
castGroup
;
return
m
ulticastAddress
;
}
}
/**
/**
...
@@ -231,8 +231,8 @@ public class DisThreadedNetworkInterface
...
@@ -231,8 +231,8 @@ public class DisThreadedNetworkInterface
try
{
try
{
// The initial value of the SO_BROADCAST socket option is FALSE
// The initial value of the SO_BROADCAST socket option is FALSE
socket
=
new
MulticastSocket
(
d
isPort
);
socket
=
new
MulticastSocket
(
getD
isPort
()
);
((
MulticastSocket
)
socket
).
joinGroup
(
group
,
ni
);
((
MulticastSocket
)
socket
).
joinGroup
(
inetSocket
,
networkInterface
);
while
(!
killed
)
{
while
(!
killed
)
{
...
@@ -263,7 +263,7 @@ public class DisThreadedNetworkInterface
...
@@ -263,7 +263,7 @@ public class DisThreadedNetworkInterface
finally
{
finally
{
if
(
socket
!=
null
&&
!
socket
.
isClosed
())
{
if
(
socket
!=
null
&&
!
socket
.
isClosed
())
{
try
{
try
{
((
MulticastSocket
)
socket
).
leaveGroup
(
group
,
ni
);
((
MulticastSocket
)
socket
).
leaveGroup
(
inetSocket
,
networkInterface
);
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
DisThreadedNetworkInterface
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
DisThreadedNetworkInterface
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
...
@@ -283,7 +283,7 @@ public class DisThreadedNetworkInterface
...
@@ -283,7 +283,7 @@ public class DisThreadedNetworkInterface
// The capacity could go up to MAX_DIS_PDU_SIZE, but this should be good for now
// The capacity could go up to MAX_DIS_PDU_SIZE, but this should be good for now
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
(
MAX_TRANSMISSION_UNIT_SIZE
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
(
MAX_TRANSMISSION_UNIT_SIZE
);
DataOutputStream
dos
=
new
DataOutputStream
(
baos
);
DataOutputStream
dos
=
new
DataOutputStream
(
baos
);
DatagramPacket
packet
=
new
DatagramPacket
(
baos
.
toByteArray
(),
baos
.
size
(),
group
);
DatagramPacket
packet
=
new
DatagramPacket
(
baos
.
toByteArray
(),
baos
.
size
(),
inetSocket
);
while
(!
killed
)
{
// keep trying on error
while
(!
killed
)
{
// keep trying on error
try
{
try
{
...
@@ -396,4 +396,12 @@ public class DisThreadedNetworkInterface
...
@@ -396,4 +396,12 @@ public class DisThreadedNetworkInterface
{
{
this
.
verbose
=
verbose
;
this
.
verbose
=
verbose
;
}
}
/**
* @param disPort the disPort value to set
*/
public
void
setDisPort
(
int
disPort
)
{
this
.
disPort
=
disPort
;
}
}
}
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