try { TFTPPacket received = bufferedReceive(); final InetAddress recdAddress = received.getAddress(); final int recdPort = received.getPort(); host = recdAddress; data.setAddress(host); sent.setAddress(host); switch (received.getType()) { case TFTPPacket.ERROR: TFTPErrorPacket error = (TFTPErrorPacket)received;
/*** * 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)); }
/*** * 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()); }
private void fireEvent(TFTPPacket packet) throws Exception { RequestEvent event = new RequestEventImpl(packet, this); try { ra_.fireEvent(event, activity_, packet.getAddress().toString()); } catch (Exception e) { transferTftp_.bufferedSend(new TFTPErrorPacket(packet.getAddress(), packet .getPort(), TFTPErrorPacket.UNDEFINED, e.getMessage())); throw e; } }
/*** * 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; }
public String getTypeDescr() { switch (req.getType()) { case TFTPPacket.READ_REQUEST: return "READ"; case TFTPPacket.WRITE_REQUEST: return "WRITE"; case TFTPPacket.DATA: return "DATA"; case TFTPPacket.ACKNOWLEDGEMENT: return "ACK"; case TFTPPacket.ERROR: return "ERROR"; default: return null; } }
private void fireEvent(TFTPPacket packet) throws Exception { RequestEvent event = new RequestEventImpl(packet, this); try { ra_.fireEvent(event, activity_, packet.getAddress().toString()); } catch (Exception e) { transferTftp_.bufferedSend(new TFTPErrorPacket(packet.getAddress(), packet .getPort(), TFTPErrorPacket.UNDEFINED, e.getMessage())); throw e; } }
_socket_.receive(__receiveDatagram); TFTPPacket newTFTPPacket = TFTPPacket.newTFTPPacket(__receiveDatagram); trace("<", newTFTPPacket); return newTFTPPacket;
public String getTypeDescr() { switch (req.getType()) { case TFTPPacket.READ_REQUEST: return "READ"; case TFTPPacket.WRITE_REQUEST: return "WRITE"; case TFTPPacket.DATA: return "DATA"; case TFTPPacket.ACKNOWLEDGEMENT: return "ACK"; case TFTPPacket.ERROR: return "ERROR"; default: return null; } }
final int recdPort = received.getPort(); final InetAddress recdAddress = received.getAddress(); if (justStarted) { justStarted = false; sent.setAddress(host); switch (received.getType()) { throw new IOException("Received unexpected packet type (" + received.getType() + ")");
public void sendError(int errorCode, String reason) { try { if (transferTftp_ != null && transferTftp_.isOpen()) { if (trc.isFineEnabled()) trc.fine(String.format("Send error - code[%d] reason[%s]", errorCode, reason)); transferTftp_.bufferedSend(new TFTPErrorPacket(tftpPacket_.getAddress(), tftpPacket_.getPort(), errorCode, reason)); transferTftp_.endBufferedOps(); } } catch (Exception e) { } shutdown(); }
/*** * Receives a TFTPPacket. * <p> * @return The TFTPPacket received. * @exception 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. * @exception 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. * @exception IOException If some other I/O error occurs. * @exception 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. * @exception 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. * @exception IOException If some I/O error occurs. ***/ public final void bufferedSend(TFTPPacket packet) throws IOException { _socket_.send(packet._newDatagram(__sendDatagram, _sendBuffer)); }
hostPort = received.getPort(); data.setPort(hostPort); if(!host.equals(received.getAddress())) host = received.getAddress(); data.setAddress(host); sent.setAddress(host); if (host.equals(received.getAddress()) && received.getPort() == hostPort) switch (received.getType()) error = new TFTPErrorPacket(received.getAddress(), received.getPort(), TFTPErrorPacket.UNKNOWN_TID, "Unexpected host or port.");
public void sendError(int errorCode, String reason) { try { if (transferTftp_ != null && transferTftp_.isOpen()) { if (trc.isFineEnabled()) trc.fine(String.format("Send error - code[%d] reason[%s]", errorCode, reason)); transferTftp_.bufferedSend(new TFTPErrorPacket(tftpPacket_.getAddress(), tftpPacket_.getPort(), errorCode, reason)); transferTftp_.endBufferedOps(); } } catch (Exception e) { } shutdown(); }
/*** * Receives a TFTPPacket. * <p> * @return The TFTPPacket received. * @exception 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. * @exception 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. * @exception IOException If some other I/O error occurs. * @exception 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. * @exception 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. * @exception IOException If some I/O error occurs. ***/ public final void bufferedSend(TFTPPacket packet) throws IOException { _socket_.send(packet._newDatagram(__sendDatagram, _sendBuffer)); }
hostPort = received.getPort(); data.setPort(hostPort); if(!host.equals(received.getAddress())) host = received.getAddress(); data.setAddress(host); sent.setAddress(host); if (host.equals(received.getAddress()) && received.getPort() == hostPort) switch (received.getType()) error = new TFTPErrorPacket(received.getAddress(), received.getPort(), TFTPErrorPacket.UNKNOWN_TID, "Unexpected host or port.");