|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.web3d.vrtp.net.DatagramStreamBuffer
DatagramStreamBuffer This is a reusable class for reading datagrams from a socket, in a platform-independent way.
The DatagramStreamBuffer reads and stores datagrams (NOT PDUs). Since this is a fairly generic operation, this should be a very reusable class. It implements the runnable interface, and generally runs in its own thread, reading data from the socket as rapidly as datagrams come in. When no datagrams are arriving, the thread blocks on the receive() method of the socket class, consuming no CPU resources.
BehaviorStreamBuffer and others can act as an adaptor to DSB, utilizing this object's generic capability to provide PDUs to higher level objects.
This uses the security classes, which provide transparent browser-independent access to things outside the sandbox. Note that use of these security classes isn't particularly secure. Since they are declared as public interfaces and classes, a rougue class can also seize them and bypass security. We live with this, since our primary objective right now is to make security go away and stop hurting us, rather than having it protect us.
mil.navy.nps.dis.BehaviorStreamBuffer
,
SecurityStrategy
Field Summary | |
(package private) java.util.Vector |
datagramBuffer
Holds datagrams received recently |
(package private) int |
datagramPort
|
(package private) java.net.InetAddress |
multicastAddress
|
(package private) boolean |
readingActive
|
protected SecurityStrategy |
strategy
platform-specific security strategy |
(package private) int |
ttl
|
(package private) boolean |
usingMulticast
|
Constructor Summary | |
DatagramStreamBuffer()
Unicast constructor: create a new unicast DSB on an ephemeral port (a port picked by the system). |
|
DatagramStreamBuffer(int pDatagramPort)
Unicast constructor: construct a new unicast datagram socket on the given port. |
|
DatagramStreamBuffer(java.lang.String pMulticastAddress,
int pDatagramPort)
Multicast constructor: given a multicast address and a port number, create a socket that is joined to that group on that port number. |
Method Summary | |
void |
cleanup()
Closes down sockets nicely |
void |
createMulticastSocket(java.net.InetAddress pMcastAddress,
java.lang.Integer pPort)
Create a multicast socket on a given port. |
protected static void |
debug(java.lang.String pDiagnostic)
Debugging output. |
void |
doRun()
doRun loops, reading packets and adding them to the list of recieved packets, until readingActive is set to false. |
protected void |
finalize()
Finalize method--used to clean up any sockets that are still open |
int |
getDatagramPort()
returns the port used by this socket |
static boolean |
getDEBUG()
Returns the status of debugging output, true = on |
java.net.InetAddress |
getMulticastAddress()
Returns the multicast address used by this socket |
java.util.Vector |
getPackets()
Returns a vector of datagrams that have been received by this object since the last time this method was called. |
boolean |
getReadingActive()
Returns the run status |
boolean |
getUsingMulticast()
returns true of this is using multicast to communicate |
static void |
main(java.lang.String[] args)
For testing purposes. |
void |
openEphemeralUnicastSocket()
Creates ephemeral unicast datagram socket, on a port picked by the system. |
void |
openUnicastSocket(java.lang.Integer pPortNumber)
Creates unicast datagram socket. |
void |
resumeReading()
|
void |
run()
run() switches on platform-secific security, then calls doRun, which does the actual work of reading from the network. |
void |
sendDatagram(java.net.DatagramPacket pDatagram)
Sends out a datagram. |
void |
sendDatagram(java.net.DatagramPacket pDatagram,
java.net.InetAddress pDestinationHost,
int pDestinationPort)
|
void |
sendDatagram(java.net.DatagramPacket pDatagram,
java.lang.String pDestinationHost,
int pDestinationPort)
Sends out a datagram to the designated destination and desitnation port. |
void |
sendStoredDatagram()
A hack. |
static void |
setDEBUG(boolean pDEBUG)
Turns on or off debugging output |
void |
setReadingActive(boolean pState)
|
void |
setTimeToLive(int pTTL)
This is JDK 1.2 specific code; if you have problems compiling under 1.1, this is probably the cause. |
void |
setTTL(byte pTTL)
Set the multicast socket time-to-live. |
void |
stopReading()
When this is set to false, the run() loop will terminate. |
protected static void |
trace(java.lang.String pDiagnostic)
Guaranteed debugging output. |
Methods inherited from class java.lang.Object |
|
Field Detail |
int datagramPort
java.net.InetAddress multicastAddress
int ttl
boolean usingMulticast
java.util.Vector datagramBuffer
boolean readingActive
protected SecurityStrategy strategy
Constructor Detail |
public DatagramStreamBuffer(int pDatagramPort)
public DatagramStreamBuffer()
public DatagramStreamBuffer(java.lang.String pMulticastAddress, int pDatagramPort)
Method Detail |
public static boolean getDEBUG()
public static void setDEBUG(boolean pDEBUG)
protected static void debug(java.lang.String pDiagnostic)
protected static void trace(java.lang.String pDiagnostic)
public java.net.InetAddress getMulticastAddress()
public int getDatagramPort()
public boolean getUsingMulticast()
public void openUnicastSocket(java.lang.Integer pPortNumber)
public void openEphemeralUnicastSocket()
public void createMulticastSocket(java.net.InetAddress pMcastAddress, java.lang.Integer pPort)
public void stopReading()
public void resumeReading()
public boolean getReadingActive()
public void setReadingActive(boolean pState)
public void run()
This is the implementation of the runnable interface. The two-step process--run calls SecurityStrategy's invokePrivilege(), which in turn calls back to this object--is required because some platforms require the security calls to be "above" in the stack. Just switching on the security parameters in strategy, and then returning and attempting to read from a socket, is not enough.
run
in interface java.lang.Runnable
public void doRun()
Called by run(); this is the essential portion of the run loop. run() has enabled platform-specific security at this point, so doRun doesn't have to worry about network sandboxes.
public java.util.Vector getPackets()
public void setTimeToLive(int pTTL)
public void setTTL(byte pTTL)
public void sendDatagram(java.net.DatagramPacket pDatagram, java.lang.String pDestinationHost, int pDestinationPort)
pDatagram
- datagram being sent outpDestinatinHost
- place being sent to, in string format, either name or dotted decimalpDestinationPort
- the port to be sent to on the remote machinepublic void sendDatagram(java.net.DatagramPacket pDatagram, java.net.InetAddress pDestinationHost, int pDestinationPort)
public void sendStoredDatagram()
public void sendDatagram(java.net.DatagramPacket pDatagram)
public void cleanup()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |