54 lines
1.8 KiB
Java
54 lines
1.8 KiB
Java
import ru.redguy.tftpserver.ErrorEvent;
|
|
import ru.redguy.tftpserver.TFTPServer;
|
|
import ru.redguy.tftpserver.TFTPread;
|
|
import ru.redguy.tftpserver.TFTPwrite;
|
|
import ru.redguy.tftpserver.datasource.FileSystem;
|
|
import ru.redguy.tftpserver.datasource.IDataSource;
|
|
import ru.redguy.tftpserver.datasource.VirtualFileSystem;
|
|
|
|
import java.io.File;
|
|
import java.net.SocketException;
|
|
|
|
public class Main {
|
|
public static void main(String[] args) {
|
|
TFTPServer tftpServer = new TFTPServer();
|
|
VirtualFileSystem ds = new VirtualFileSystem();
|
|
ds.addFile("a.gradle",new File("build.gradle"));
|
|
try {
|
|
tftpServer.start(1000,false,ds);
|
|
} catch (SocketException e) {
|
|
e.printStackTrace();
|
|
}
|
|
System.out.println(tftpServer.getPort());
|
|
tftpServer.onError(new ErrorEvent() {
|
|
@Override
|
|
public void onPacketReceiveException(Exception exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
|
|
@Override
|
|
public void onPacketReadException(Exception exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
|
|
@Override
|
|
public void onPacketWriteException(Exception exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
|
|
@Override
|
|
public void onClientReadException(Exception exception, TFTPread tftPread) {
|
|
exception.printStackTrace();
|
|
System.out.println(tftPread.fileName());
|
|
}
|
|
|
|
@Override
|
|
public void onClientWriteException(Exception exception, TFTPwrite tftPwrite) {
|
|
exception.printStackTrace();
|
|
System.out.println(tftPwrite.fileName());
|
|
}
|
|
});
|
|
while (true) {}
|
|
}
|
|
}
|