-1

I wrote a simple TFTP client in Java, using org.apache.commons.net.tftp.TFTPClient. As server for testing i use tftpd64 and while it's running, everything works fine. But when there isn't any server running, functions sendFile() and receiveFile() are returning.

I'm trying to catch SocketTimeoutExeption, but functions don't throw anything. I've checked packets with Wireshark, and I can see a Write Request packet, but of course there is no response, since I don't have server running. How can i check, that there were no response?

KrzysztofW
  • 57
  • 4

1 Answers1

0

TFTP is an UDP protocol. We have not connection and we have not error control. If server is running and it responds, it sends to your client an UDP datagram that you are not sure to receive. You can not have information "datagram is lost" with UDP. Timeout is managed by your implementation of TFTP.

According to commons apache code and apache TFTPClient doc, you already have timeout management.

  • setDefaultTimeout(int timeout) : Set the default timeout in milliseconds to use when opening a socket.
  • setSoTimeout(int timeout) : Set the timeout in milliseconds of a currently open connection.
  • setMaxTimeouts(int numTimeouts) : Sets the maximum number of times a receive attempt is allowed to timeout during a receiveFile() or sendFile() operation before ending attempts to retry the receive and failing.

  • sendFile and receiveFile throw IOException. Maybe SocketTimeoutException is never thrown because timeout expiration is not managed by socket.

Azwaw
  • 548
  • 3
  • 12
  • I know, but as far as I understand, when client sends request, it starts to wait for response and when it is not getting it for any reason, it should fail after it exceeds the timeout. Am I gettint it right and is there any way to detect this with TFTPClient implementation? – KrzysztofW Feb 03 '15 at 15:05
  • By default defaultTimeout is 0. It is equivalent to an infinit timeout. Try to change this value – Azwaw Feb 03 '15 at 15:10
  • Ok, problem was caused by default maxTimeouts. After setting it (and other timeouts as well) to not 0 , functions started to throw IOExeptions. Thanks ;) – KrzysztofW Feb 03 '15 at 15:20