public class TFTPServer extends Object implements Runnable
 Example usage is below:
 
 
 public static void main(String[] args) throws Exception
  {
      if (args.length != 1)
      {
          System.out
                  .println("You must provide 1 argument - the base path for the server to serve from.");
          System.exit(1);
      }
      TFTPServer ts = new TFTPServer(new File(args[0]), new File(args[0]), GET_AND_PUT);
      ts.setSocketTimeout(2000);
      System.out.println("TFTP Server running.  Press enter to stop.");
      new InputStreamReader(System.in).read();
      ts.shutdown();
      System.out.println("Server shut down.");
      System.exit(0);
  }
 
| Modifier and Type | Class and Description | 
|---|---|
| static class  | TFTPServer.ServerMode | 
| private class  | TFTPServer.TFTPTransfer | 
| Modifier and Type | Field and Description | 
|---|---|
| private static int | DEFAULT_TFTP_PORT | 
| private PrintStream | log_ | 
| private PrintStream | logError_ | 
| private int | maxTimeoutRetries_ | 
| private TFTPServer.ServerMode | mode_ | 
| private static PrintStream | nullStream | 
| private int | port_ | 
| private Exception | serverException | 
| private File | serverReadDirectory_ | 
| private org.apache.commons.net.tftp.TFTP | serverTftp_ | 
| private Thread | serverThread | 
| private File | serverWriteDirectory_ | 
| private boolean | shutdownServer | 
| private int | socketTimeout_ | 
| private HashSet<TFTPServer.TFTPTransfer> | transfers_ | 
| Constructor and Description | 
|---|
| TFTPServer(File serverReadDirectory,
          File serverWriteDirectory,
          int port,
          TFTPServer.ServerMode mode,
          PrintStream log,
          PrintStream errorLog)Start a TFTP Server on the specified port. | 
| TFTPServer(File serverReadDirectory,
          File serverWriteDirectory,
          TFTPServer.ServerMode mode)Start a TFTP Server on the default port (69). | 
| Modifier and Type | Method and Description | 
|---|---|
| protected void | finalize() | 
| int | getMaxTimeoutRetries()Get the current value for maxTimeoutRetries | 
| int | getSocketTimeout()The current socket timeout used during transfers in milliseconds. | 
| boolean | isRunning()check if the server thread is still running. | 
| private void | launch(File serverReadDirectory,
      File serverWriteDirectory) | 
| void | run() | 
| void | setLog(PrintStream log)Set the stream object to log debug / informational messages. | 
| void | setLogError(PrintStream logError)Set the stream object to log error messsages. | 
| void | setMaxTimeoutRetries(int retries)Set the max number of retries in response to a timeout. | 
| void | setSocketTimeout(int timeout)Set the socket timeout in milliseconds used in transfers. | 
| void | shutdown()Stop the tftp server (and any currently running transfers) and release all opened network
 resources. | 
private static final int DEFAULT_TFTP_PORT
private HashSet<TFTPServer.TFTPTransfer> transfers_
private volatile boolean shutdownServer
private org.apache.commons.net.tftp.TFTP serverTftp_
private File serverReadDirectory_
private File serverWriteDirectory_
private int port_
private Exception serverException
private TFTPServer.ServerMode mode_
private static final PrintStream nullStream
private PrintStream log_
private PrintStream logError_
private int maxTimeoutRetries_
private int socketTimeout_
private Thread serverThread
public TFTPServer(File serverReadDirectory, File serverWriteDirectory, TFTPServer.ServerMode mode) throws IOException
serverReadDirectory - directory for GET requestsserverWriteDirectory - directory for PUT requestsmode - A value as specified above.IOException - if the server directory is invalid or does not exist.public TFTPServer(File serverReadDirectory, File serverWriteDirectory, int port, TFTPServer.ServerMode mode, PrintStream log, PrintStream errorLog) throws IOException
serverReadDirectory - directory for GET requestsserverWriteDirectory - directory for PUT requestsmode - A value as specified above.log - Stream to write log message to. If not provided, uses System.outerrorLog - Stream to write error messages to. If not provided, uses System.err.IOException - if the server directory is invalid or does not exist.public void setMaxTimeoutRetries(int retries)
retries - public int getMaxTimeoutRetries()
public void setSocketTimeout(int timeout)
public int getSocketTimeout()
private void launch(File serverReadDirectory, File serverWriteDirectory) throws IOException
IOExceptionprotected void finalize()
                 throws Throwable
public boolean isRunning()
                  throws Exception
Exception - throws the exception that stopped the server if the server is stopped from
             an exception.public void shutdown()
public void setLog(PrintStream log)
log - public void setLogError(PrintStream logError)
logError -