Stop and Wait


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: Stop and Wait

  1. #1
    Join Date
    Oct 2002
    Posts
    1

    Stop and Wait



    I am a new student in Java programming, and we haven't studied java networking yet, but I'm taking another couse called Data and Computer Communications which require us to write two programs in Java that will communicate with each other, it's meant to make me experience networking and it's not a java test, but in order to do that I have to have those programs. I appreciate the help:

    Stop-And-Wait

    I need to write two programs, a Sender and a Receiver, communicate with UDP. The Sender gets a text string from the keyboard (user input). The communication canal can only handle a packet of 10 bytes (we simulate this by not sending a packet of more than 10 bytes). In other words, the Sender must break down the messages into small chunks and sends them one at a time. Each packet will also have 3 bytes of control information, which means that the data size in each packet can not exceed 7.

    The message format of each packet is:

    | seq | cntrl | data | check |

    where seq(1 byte) is a sequence number, data (<=7 bytes), check (1 byte),
    cntrl includes

    | type | flag | len |

    where type(1 bit) =0 for data packet, 1 for ACK/NAK;
    flag(1 bit) = 1 for the last packet in the message, 0 if the packet is not the last one.
    flag(1 bit) = 0 for ACK, 1 for NAK (for a receipt packet).
    len(6 bits) = data length (number of bytes) for data packet; 0 for a receipt packet.

    In each message, the sequence number (seq) for the first packet = 0.
    When a packet is created, all the fields will be filled except for check.
    The checksum is created by adding the remaining bytes (<=9) modulo-256, and this is filled in the check field.

    We simulate the transfer error by creating an instance of the class Error (attached).
    A suitable number for the error frequency, is 5 to 10 (i.e. 0.5 to 1 % error chance per bit). Each bit is to filtered by Error ( buf = error.error(buf); ).

    When the Receiver gets a packet, it checks the checksum and if it is correct, it sends an ACK, otherwise it sends a NAK. Notice that even those need to be filtered through Error, which means that they are also open for transfer error.

    When the Sender gets an ACK or a NAK, it checks the checksum. If the checksum is correct for an ACK, it sends the next packet if there are more packets to send. If the checksum is correct for a NAK or it is incorrect (for both), the Sender sends the last sent packet again. Note that even then a sequence number is required.

    A number of error situations must be dealt with: when a data packet is corrupted, when an ACK is corrupted, or when a NAK is corrupted. Men we know that the packet always is delivered.

    When the last packet is received, the Receiver write a message on the screen, resets itself, and waits again.

    Thanx
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center