/** * This is a special method to perform a more efficient packet receive. 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. * * <p> * * @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 bufferedReceive() throws IOException, InterruptedIOException, SocketException, TFTPPacketException { __receiveDatagram.setData(__receiveBuffer); __receiveDatagram.setLength(__receiveBuffer.length); _socket_.receive(__receiveDatagram); return TFTPPacket.newTFTPPacket(__receiveDatagram); }
/** * Receives a TFTPPacket. * * <p> * * @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); return TFTPPacket.newTFTPPacket(packet); }
/** * Sends a TFTP packet to its destination. * * <p> * * @param packet The TFTP packet to send. * @throws IOException If some I/O error occurs. * */ public final void send(TFTPPacket packet) throws IOException { _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. * * <p> * * @param packet The TFTP packet to send. * @throws IOException If some I/O error occurs. * */ public final void bufferedSend(TFTPPacket packet) throws IOException { _socket_.send(packet._newDatagram(__sendDatagram, _sendBuffer)); }