verinec.adaptation.snmp.tftpserver
Class Download

java.lang.Object
  extended by verinec.adaptation.snmp.tftpserver.Download

public class Download
extends Object

Class responsible for managing the download process for TFTP service. We are the server, so this handles sending a file to a client.

Most of the source was taken from www.it.rit.edu/~netsyslb/vksf522/class_examples/Day09_TFTPServer/Download.pdf
I removed the gui part.

Version:
1.0
Author:
christoph.ehret at unifr.ch

Nested Class Summary
private  class Download.Listener
          Private class that listens on a socket to receive datagrams.
 
Field Summary
private  long bytesToSend
          # of bytes left to download.
private  InetAddress clientAddress
          the address of the server.
private  int clientPort
          port to contact server on (69 per default).
private  DatagramPacket dgram
          unparsed TFTP packet.
private static int DOWNLOADING
          State: Currently downloading.
private static int ENDINGDL
          State: Just finishing downloading.
private  DataInputStream fistream
          input stream for reading the downloaded file.
private  String fp
           
private  byte[] lastBlock
          last block sent.
private  int lastBlockNo
          block # of last block sent.
private  DatagramPacket lastPacket
          last packet sent (for resends).
private  String lastPacketDesc
          description of last packet sent (for logs).
private  Download.Listener listener
          socket listener for incoming packets.
private  String localDirName
          name of the local download directory.
private  String localName
          name of the file.
private  Logger logger
          debugging.
private  DatagramSocket socket
          socket used to communicate with server.
private  int state
          state of the download.
private  TFTPPacket tftp
          parsed packet.
private  Timer timer
          timer used for resends.
private  int timerCount
          number of times the timer has expired.
(package private)  ActionListener timerExpired
           
 
Constructor Summary
Download(DatagramPacket pkt, TFTPPacket tftp, String localDirName)
          Creates a Download instance for downloading data
 
Method Summary
private  void doACK(TFTPPacket pkt)
           
private  void doERROR(TFTPPacket pkt)
           
private  void doRRQ()
           
private  void endDownload()
           
private  void processPacket(DatagramPacket pkt)
           
 void resendPacket()
          Resends last sent packet if an error occured with sending of data.
private  void sendError(int code)
           
private  void sendNextBlock()
           
private  void sendPacket(DatagramPacket pkt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fp

private String fp

logger

private Logger logger
debugging.


state

private int state
state of the download.


DOWNLOADING

private static final int DOWNLOADING
State: Currently downloading.

See Also:
Constant Field Values

ENDINGDL

private static final int ENDINGDL
State: Just finishing downloading.

See Also:
Constant Field Values

dgram

private DatagramPacket dgram
unparsed TFTP packet.


tftp

private TFTPPacket tftp
parsed packet.


localDirName

private String localDirName
name of the local download directory.


localName

private String localName
name of the file.


clientAddress

private InetAddress clientAddress
the address of the server.


clientPort

private int clientPort
port to contact server on (69 per default).


fistream

private DataInputStream fistream
input stream for reading the downloaded file.


lastBlockNo

private int lastBlockNo
block # of last block sent.


lastBlock

private byte[] lastBlock
last block sent.


bytesToSend

private long bytesToSend
# of bytes left to download.


timer

private Timer timer
timer used for resends.


timerCount

private int timerCount
number of times the timer has expired.


lastPacket

private DatagramPacket lastPacket
last packet sent (for resends).


lastPacketDesc

private String lastPacketDesc
description of last packet sent (for logs).


socket

private DatagramSocket socket
socket used to communicate with server.


listener

private Download.Listener listener
socket listener for incoming packets.


timerExpired

ActionListener timerExpired
Constructor Detail

Download

public Download(DatagramPacket pkt,
                TFTPPacket tftp,
                String localDirName)
Creates a Download instance for downloading data

Parameters:
pkt - Unparsed TFTP packet
tftp - Parsed TFTP packet
localDirName - Local download directory
See Also:
TFTPPacket
Method Detail

sendNextBlock

private void sendNextBlock()

resendPacket

public void resendPacket()
Resends last sent packet if an error occured with sending of data.


sendError

private void sendError(int code)

sendPacket

private void sendPacket(DatagramPacket pkt)
                 throws IOException
Throws:
IOException

endDownload

private void endDownload()

processPacket

private void processPacket(DatagramPacket pkt)

doRRQ

private void doRRQ()

doACK

private void doACK(TFTPPacket pkt)

doERROR

private void doERROR(TFTPPacket pkt)

Copyright © 2005 Verinec, DIUF