/*** * Sends a TFTP packet to its destination. * * @param packet The TFTP packet to send. * @throws IOException If some I/O error occurs. ***/ public final void send(TFTPPacket packet) throws IOException { trace(">", packet); _socket_.send(packet.newDatagram()); }
/*** * This is a special method to perform a more efficient packet send. * It should only be used after calling * {@link #beginBufferedOps beginBufferedOps() }. beginBufferedOps() * initializes a set of buffers used internally that prevent the new * allocation of a DatagramPacket and byte array for each send and receive. * To use these buffers you must call the bufferedReceive() and * bufferedSend() methods instead of send() and receive(). You must * also be certain that you don't manipulate the resulting packet in * such a way that it interferes with future buffered operations. * For example, a TFTPDataPacket received with bufferedReceive() will * have a reference to the internal byte buffer. You must finish using * this data before calling bufferedReceive() again, or else the data * will be overwritten by the the call. * * @param packet The TFTP packet to send. * @throws IOException If some I/O error occurs. ***/ public final void bufferedSend(TFTPPacket packet) throws IOException { trace(">", packet); _socket_.send(packet._newDatagram(__sendDatagram, _sendBuffer)); }
/*** * Receives a TFTPPacket. * * @return The TFTPPacket received. * @throws InterruptedIOException If a socket timeout occurs. The * Java documentation claims an InterruptedIOException is thrown * on a DatagramSocket timeout, but in practice we find a * SocketException is thrown. You should catch both to be safe. * @throws SocketException If a socket timeout occurs. The * Java documentation claims an InterruptedIOException is thrown * on a DatagramSocket timeout, but in practice we find a * SocketException is thrown. You should catch both to be safe. * @throws IOException If some other I/O error occurs. * @throws TFTPPacketException If an invalid TFTP packet is received. ***/ public final TFTPPacket receive() throws IOException, InterruptedIOException, SocketException, TFTPPacketException { DatagramPacket packet; packet = new DatagramPacket(new byte[PACKET_SIZE], PACKET_SIZE); _socket_.receive(packet); TFTPPacket newTFTPPacket = TFTPPacket.newTFTPPacket(packet); trace("<", newTFTPPacket); return newTFTPPacket; }
trace("<", newTFTPPacket); return newTFTPPacket;