public class Receiver
extends java.lang.Object
| Constructor and Description |
|---|
Receiver(java.lang.String file)
Constructs a Receiver to obtain the image file transmitted.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
askForMissingPacket(int seq)
Asks for retransmitting the packet with a sequence number.
|
SimplePacket |
askForNextPacket()
Returns the next packet.
|
boolean |
askForRetransmit(SimplePacket pkt)
Asks for retransmitting the packet.
|
void |
displayList()
Outputs the formatted content in the PacketLinkedList buffer.
|
PacketLinkedList<SimplePacket> |
getListBuffer()
Returns the PacketLinkedList buffer in the receiver
|
static void |
main(java.lang.String[] args)
Initiates a Receiver to reconstruct collected packets and open the Image
file, which is specified by args[0].
|
void |
openImage()
Opens the image file by merging the content in the maintained list
buffer.
|
void |
reconstructFile()
Reconstructs the file by arranging the
PacketLinkedList in
correct order. |
boolean |
validImageContent()
Returns true if the maintained list buffer has a valid image content.
|
boolean |
validImageHeader()
Returns if the maintained list buffer has a valid image header
|
public Receiver(java.lang.String file)
file - the filename you want to receivepublic PacketLinkedList<SimplePacket> getListBuffer()
public boolean askForRetransmit(SimplePacket pkt)
askForNextPacket().
Notice that ONLY packet with invalid checksum will be retransmitted.pkt - the packet with bad checksumpublic boolean askForMissingPacket(int seq)
askForNextPacket(). Notice that ONLY missing
packet will be retransmitted. Pass seq=0 if the missing packet is the
"End of Streaming Notification" packet.seq - the sequence number of the requested missing packetpublic SimplePacket askForNextPacket()
public boolean validImageContent()
public boolean validImageHeader()
public void displayList()
public void reconstructFile()
PacketLinkedList in
correct order. It uses askForNextPacket() to get packets until
no more packet to receive. It eliminates the duplicate packets and asks
for retransmitting when getting a packet with invalid checksum.public void openImage()
BadImageHeaderException - if the maintained list buffer has an
invalid image headerBadImageContentException - if the maintained list buffer has an
invalid image contentpublic static void main(java.lang.String[] args)
args - command line arguments