All Packages Class Hierarchy This Package Previous Next Index
Class AcmeNet.Util.NetworkInterface
AcmeNet.Util.NetworkInterface
- public class NetworkInterface
A "network adapter" that can be used to send and receive AcmeNet packets.
AcmeNet, like the Internet on which it is built, is unreliable. Although the
network makes its "best effort" to deliver every packet, there is no guarantee
that any particular packet will be delivered, nor is there a guarantee that packets
will be delivered in the same order in which they were sent.
- See Also:
- NetAddress
-
MaxPacketLength
- The maximum allowable packet length
-
packetDropProbability
- The probability that any packet will be "artificially" lost.
-
socket
- The Internet-domain socket that is actually used to send and receive packets.
-
NetworkInterface()
- Create a NetworkInterface at any available NetAddress
-
NetworkInterface(NetAddress)
- Create a NetworkInterface at a specified NetAddress
-
getAddress()
-
-
getOutPacketStream(NetAddress)
- Get an output stream that can be used to build a packet to be sent on this NetworkInterface.
-
getPacketQueue()
- Get a queue object that can be used to retrieve the packets that arrive at this
NetworkInterface.
-
run()
- Executed by a daemon thread.
-
sendBytes(NetAddress, byte[])
- Send a packet of data across AcmeNet.
MaxPacketLength
public static final int MaxPacketLength
- The maximum allowable packet length
packetDropProbability
public static double packetDropProbability
- The probability that any packet will be "artificially" lost.
Setting this to a non-zero value can be helpful when testing code that is
supposed to recover from packet loss.
socket
protected DatagramSocket socket
- The Internet-domain socket that is actually used to send and receive packets.
NetworkInterface
public NetworkInterface() throws InternalException
- Create a NetworkInterface at any available NetAddress
- Throws: InternalException
- something pretty weird is happening
NetworkInterface
public NetworkInterface(NetAddress requiredAddress) throws AddressUnavailableException
- Create a NetworkInterface at a specified NetAddress
- Parameters:
- requiredAddress - the location at which the new NetAddress must be created
- Throws: AddressUnavailableException
- the requested address was not available
sendBytes
protected void sendBytes(NetAddress dest,
byte data[]) throws PacketTooLargeException, IOException
- Send a packet of data across AcmeNet. If there is no Acme process at the destination
address, the packet will silently vanish into oblivion. Even if there is a
process at the destination, the network may lose the packet anyway.
- Parameters:
- dest - the address to send the packet to
- data - an array containing the data to be sent
- Throws: IOException
- some I/O error occured
- Throws: PacketTooLargeException
- the packet would have been larger than MaxPacketLength
getAddress
public NetAddress getAddress()
- Returns:
- the address of this NetworkInterface
getOutPacketStream
public DataOutputStream getOutPacketStream(NetAddress dest)
- Get an output stream that can be used to build a packet to be sent on this NetworkInterface.
You can use the normal java.io.DataOutputStream methods to append data to the packet.
When you flush the stream, the packet will be sent.
- Parameters:
- dest - the address that the packet should (eventually) be sent to
- Returns:
- an output stream into which the packet can be accumulated
getPacketQueue
public PacketQueue getPacketQueue()
- Get a queue object that can be used to retrieve the packets that arrive at this
NetworkInterface.
- Returns:
- s a queue that where all arriving packets will be put
run
public void run()
- Executed by a daemon thread.
All Packages Class Hierarchy This Package Previous Next Index