|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.net.tftp.TFTPServer
public class TFTPServer
A fully multi-threaded tftp server. Can handle multiple clients at the same time. Implements RFC 1350 and wrapping block numbers for large file support. To launch, just create an instance of the class. An IOException will be thrown if the server fails to start for reasons such as port in use, port denied, etc. To stop, use the shutdown method. To check to see if the server is still running (or if it stopped because of an error), call the isRunning() method. By default, events are not logged to stdout/stderr. This can be changed with the setLog and setLogError methods.
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);
}
Nested Class Summary | |
---|---|
static class |
TFTPServer.ServerMode
|
Constructor Summary | |
---|---|
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). |
Method Summary | |
---|---|
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. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
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.Method Detail |
---|
public void setMaxTimeoutRetries(int retries)
retries
- public int getMaxTimeoutRetries()
public void setSocketTimeout(int timeout)
public int getSocketTimeout()
protected void finalize() throws Throwable
finalize
in class Object
Throwable
public boolean isRunning() throws Exception
Exception
- throws the exception that stopped the server if the server is stopped from
an exception.public void run()
run
in interface Runnable
public void shutdown()
public void setLog(PrintStream log)
log
- public void setLogError(PrintStream logError)
logError
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |