Package edu.nps.moves.dis7.utilities
Class DisThreadedNetworkInterface
java.lang.Object
edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface
This is a thread-safe, multicast DIS network interface class.
- Since:
- Jul 29, 2019
- Author:
- Mike Bailey, jmbailey@nps.edu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Stores data for further processingstatic interface
Pdu listener class and interfacestatic interface
Raw pdu listener class and interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic String
Default multicast group address239.1.2.3
for send and receive connections.static int
Default socket port3000
, matches Wireshark DIS capture defaultstatic int
MTU 8192: TODO this has actually been superseded by a larger buffer size, but good enough for nowstatic int
MTU 1500: size of an Ethernet frame, common value to avoid packet segmentation -
Constructor Summary
ConstructorsConstructorDescriptionObject constructor using default multicast address and portDisThreadedNetworkInterface(String address, int port)
Object constructor using specified multicast address and port -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener(DisThreadedNetworkInterface.PduListener newListener)
Add a listener to accept all pdu typesvoid
addListener(DisThreadedNetworkInterface.PduListener newListener, DisPduType disPduType)
Add a listener to accept only pdus of a given typevoid
Add a listener to accept pdus of all types in the form of a byte arrayvoid
close()
Terminate the instance after completion of pending send/receive activity.static NetworkInterface
Find proper IPV4 interface on this computer for use with the djs addressvoid
Finish pending send/receive activity and then close.Get current multicast (or unicast) network address for send and receive connections.Get simple descriptor (such as parent class name) for this network interface, used in trace statementsint
Deprecated.Deprecated.int
getPort()
Get network port used, multicast or unicast.boolean
Whether or not trace statements are provided when packets are sent or received.boolean
Whether or not trace statements include timestamp values.boolean
Whether or not trace statements are provided when packets are received.boolean
Whether or not trace statements are provided when packets are sent.void
kill()
Deprecated.static void
Main method for testing.void
removeListener(DisThreadedNetworkInterface.PduListener priorListener)
Remove previously added listenervoid
Remove previously added raw listenervoid
Send the given pdu to the network using the IP address and port given to the constructorvoid
setAddress(String newAddress)
Network address for send and receive connections.void
setDescriptor(String newDescriptor)
Set new simple descriptor (such as parent class name) for this network interface, used in trace statementsvoid
setPort(int newPortValue)
/** Set network port used, multicast or unicast.void
setVerbose(boolean newValue)
Set whether or not trace statements are provided when packets are sent or received.void
setVerboseIncludesTimestamp(boolean verboseIncludesTimestamp)
Set whether or not trace statements include timestamp values.void
setVerboseReceipt(boolean newValue)
Set whether or not trace statements are provided when packets are received.void
setVerboseSending(boolean newValue)
Set whether or not trace statements are provided when packets are sent.void
start()
Can be used to restart DisThreadedNetworkInterface if closed.
-
Field Details
-
DEFAULT_DIS_ADDRESS
Default multicast group address239.1.2.3
for send and receive connections. -
DEFAULT_DIS_PORT
public static int DEFAULT_DIS_PORTDefault socket port3000
, matches Wireshark DIS capture default -
MAX_DIS_PDU_SIZE
public static final int MAX_DIS_PDU_SIZEMTU 8192: TODO this has actually been superseded by a larger buffer size, but good enough for now- See Also:
- Constant Field Values
-
MAX_TRANSMISSION_UNIT_SIZE
public static final int MAX_TRANSMISSION_UNIT_SIZEMTU 1500: size of an Ethernet frame, common value to avoid packet segmentation- See Also:
- Constant Field Values
-
-
Constructor Details
-
DisThreadedNetworkInterface
public DisThreadedNetworkInterface()Object constructor using default multicast address and port -
DisThreadedNetworkInterface
Object constructor using specified multicast address and port- Parameters:
address
- the multicast group or unicast address to utilizeport
- the multicast port to utilize
-
-
Method Details
-
main
Main method for testing.- Parameters:
args
- command-line arguments are an array of optional String parameters that are passed from execution environment during invocation- See Also:
- Java Tutorials: A Closer Look at the "Hello World!" Application
-
addListener
public void addListener(DisThreadedNetworkInterface.PduListener newListener, DisPduType disPduType)Add a listener to accept only pdus of a given type- Parameters:
newListener
- listener instance implementing the RawPduListener interfacedisPduType
- Pdu type
-
addListener
Add a listener to accept all pdu types- Parameters:
newListener
- listener instance implementing the RawPduListener interface
-
removeListener
Remove previously added listener- Parameters:
priorListener
- listener instance implementing the RawPduListener interface
-
addRawListener
Add a listener to accept pdus of all types in the form of a byte array- Parameters:
lis
- listener instance implementing the RawPduListener interface
-
removeRawListener
Remove previously added raw listener- Parameters:
lis
- listener instance implementing the RawPduListener interface
-
getMulticastGroup
Deprecated.Method renamed asgetAddress()
so use that method instead.- Returns:
- current multicast address value
-
getAddress
Get current multicast (or unicast) network address for send and receive connections.- Returns:
- current multicast address value
- See Also:
- https://en.wikipedia.org/wiki/Multicast_address
-
setAddress
Network address for send and receive connections.- Parameters:
newAddress
- the new network address to set- See Also:
- https://en.wikipedia.org/wiki/Multicast_address
-
send
Send the given pdu to the network using the IP address and port given to the constructor- Parameters:
pdu
- the pdu to send
-
start
public void start()Can be used to restart DisThreadedNetworkInterface if closed. Create datagram socket if not already available; can also be invoked by either sender or receiver thread to ensure datagram socket is open. -
kill
Deprecated.Method renamed asclose()
so use that method instead. -
finishOperations
public void finishOperations()Finish pending send/receive activity and then close. -
close
public void close()Terminate the instance after completion of pending send/receive activity. Synchronized to prevent interleaved invocation. -
findIpv4Interface
Find proper IPV4 interface on this computer for use with the djs address- Returns:
- a network interface to use to join a multicast group
-
setVerbose
public void setVerbose(boolean newValue)Set whether or not trace statements are provided when packets are sent or received.- Parameters:
newValue
- the verbose status to set. Also resets verboseReceipt and verboseSending to match.- See Also:
verboseReceipt
,verboseSending
-
hasVerboseOutput
public boolean hasVerboseOutput()Whether or not trace statements are provided when packets are sent or received.- Returns:
- the verbose status
- See Also:
verboseReceipt
,verboseSending
-
setVerboseReceipt
public void setVerboseReceipt(boolean newValue)Set whether or not trace statements are provided when packets are received.- Parameters:
newValue
- the verboseReceipt status to set- See Also:
verbose
,verboseSending
-
hasVerboseReceipt
public boolean hasVerboseReceipt()Whether or not trace statements are provided when packets are received.- Returns:
- the verboseReceipt status
-
setVerboseSending
public void setVerboseSending(boolean newValue)Set whether or not trace statements are provided when packets are sent.- Parameters:
newValue
- the verboseSending status to set- See Also:
verbose
,verboseReceipt
-
hasVerboseSending
public boolean hasVerboseSending()Whether or not trace statements are provided when packets are sent.- Returns:
- the verboseSending status
-
hasVerboseOutputIncludesTimestamp
public boolean hasVerboseOutputIncludesTimestamp()Whether or not trace statements include timestamp values.- Returns:
- the verboseIncludesTimestamp value
-
setVerboseIncludesTimestamp
public void setVerboseIncludesTimestamp(boolean verboseIncludesTimestamp)Set whether or not trace statements include timestamp values.- Parameters:
verboseIncludesTimestamp
- the value to set
-
getDisPort
Deprecated.Method renamed asgetPort()
so use that method instead.- Returns:
- current port value
-
getPort
public int getPort()Get network port used, multicast or unicast.- Returns:
- current port value
- See Also:
- https://en.wikipedia.org/wiki/Port_(computer_networking)
-
setPort
public void setPort(int newPortValue)/** Set network port used, multicast or unicast.- Parameters:
newPortValue
- the disPort value to set- See Also:
- https://en.wikipedia.org/wiki/Port_(computer_networking)
-
getDescriptor
Get simple descriptor (such as parent class name) for this network interface, used in trace statements- Returns:
- simple descriptor name
-
setDescriptor
Set new simple descriptor (such as parent class name) for this network interface, used in trace statements- Parameters:
newDescriptor
- simple descriptor name
-