Fields Summary |
---|
static final int | MIN_PACKET_SIZEThe minimum size of a packet. This is 4 bytes. It is enough
to store the opcode and blocknumber or other required data
depending on the packet type. |
public static final int | READ_REQUESTThis is the actual TFTP spec
identifier and is equal to 1.
Identifier returned by {@link #getType getType()}
indicating a read request packet. |
public static final int | WRITE_REQUESTThis is the actual TFTP spec
identifier and is equal to 2.
Identifier returned by {@link #getType getType()}
indicating a write request packet. |
public static final int | DATAThis is the actual TFTP spec
identifier and is equal to 3.
Identifier returned by {@link #getType getType()}
indicating a data packet. |
public static final int | ACKNOWLEDGEMENTThis is the actual TFTP spec
identifier and is equal to 4.
Identifier returned by {@link #getType getType()}
indicating an acknowledgement packet. |
public static final int | ERRORThis is the actual TFTP spec
identifier and is equal to 5.
Identifier returned by {@link #getType getType()}
indicating an error packet. |
public static final int | SEGMENT_SIZEThe TFTP data packet maximum segment size in bytes. This is 512
and is useful for those familiar with the TFTP protocol who want
to use the {@link org.apache.commons.net.tftp.TFTP}
class methods to implement their own TFTP servers or clients. |
int | _typeThe type of packet. |
int | _portThe port the packet came from or is going to. |
InetAddress | _addressThe host the packet is going to be sent or where it came from. |
Methods Summary |
---|
abstract java.net.DatagramPacket | _newDatagram(java.net.DatagramPacket datagram, byte[] data)This is an abstract method only available within the package for
implementing efficient datagram transport by elminating buffering.
It takes a datagram as an argument, and a byte buffer in which
to store the raw datagram data. Inside the method, the data
should be set as the datagram's data and the datagram returned.
|
public final java.net.InetAddress | getAddress()Returns the address of the host where the packet is going to be sent
or where it came from.
return _address;
|
public final int | getPort()Returns the port where the packet is going to be sent
or where it came from.
return _port;
|
public final int | getType()Returns the type of the packet.
return _type;
|
public abstract java.net.DatagramPacket | newDatagram()Creates a UDP datagram containing all the TFTP packet
data in the proper format.
This is an abstract method, exposed to the programmer in case he
wants to implement his own TFTP client instead of using
the {@link org.apache.commons.net.tftp.TFTPClient}
class.
Under normal circumstances, you should not have a need to call this
method.
|
public static final org.apache.commons.net.tftp.TFTPPacket | newTFTPPacket(java.net.DatagramPacket datagram)When you receive a datagram that you expect to be a TFTP packet, you use
this factory method to create the proper TFTPPacket object
encapsulating the data contained in that datagram. This method is the
only way you can instantiate a TFTPPacket derived class from a
datagram.
byte[] data;
TFTPPacket packet = null;
if (datagram.getLength() < MIN_PACKET_SIZE)
throw new TFTPPacketException(
"Bad packet. Datagram data length is too short.");
data = datagram.getData();
switch (data[1])
{
case READ_REQUEST:
packet = new TFTPReadRequestPacket(datagram);
break;
case WRITE_REQUEST:
packet = new TFTPWriteRequestPacket(datagram);
break;
case DATA:
packet = new TFTPDataPacket(datagram);
break;
case ACKNOWLEDGEMENT:
packet = new TFTPAckPacket(datagram);
break;
case ERROR:
packet = new TFTPErrorPacket(datagram);
break;
default:
throw new TFTPPacketException(
"Bad packet. Invalid TFTP operator code.");
}
return packet;
|
public final void | setAddress(java.net.InetAddress address)Sets the host address where the packet is going to be sent.
_address = address;
|
public final void | setPort(int port)Sets the port where the packet is going to be sent.
_port = port;
|