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

Variable Index

 o MaxPacketLength
The maximum allowable packet length
 o packetDropProbability
The probability that any packet will be "artificially" lost.
 o socket
The Internet-domain socket that is actually used to send and receive packets.

Constructor Index

 o NetworkInterface()
Create a NetworkInterface at any available NetAddress
 o NetworkInterface(NetAddress)
Create a NetworkInterface at a specified NetAddress

Method Index

 o getAddress()
 o getOutPacketStream(NetAddress)
Get an output stream that can be used to build a packet to be sent on this NetworkInterface.
 o getPacketQueue()
Get a queue object that can be used to retrieve the packets that arrive at this NetworkInterface.
 o run()
Executed by a daemon thread.
 o sendBytes(NetAddress, byte[])
Send a packet of data across AcmeNet.

Variables

 o MaxPacketLength
 public static final int MaxPacketLength
The maximum allowable packet length

 o 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.

 o socket
 protected DatagramSocket socket
The Internet-domain socket that is actually used to send and receive packets.

Constructors

 o NetworkInterface
 public NetworkInterface() throws InternalException
Create a NetworkInterface at any available NetAddress

Throws: InternalException
something pretty weird is happening
 o 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

Methods

 o 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
 o getAddress
 public NetAddress getAddress()
Returns:
the address of this NetworkInterface
 o 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
 o 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
 o run
 public void run()
Executed by a daemon thread.


All Packages  Class Hierarchy  This Package  Previous  Next  Index