Week 1 - Stop-and-Wait ARQ

Distributed Systems and Network Programming - Spring 2023

Task

Client Implementation

Server Implementation (your task)

  1. Parse one integer argument, the port number to listen on.
  2. Create a UDP socket and start listening for incoming messages on 0.0.0.0:<port>.
    • The server should use a fixed receiver buffer size of 20480 bytes (20 Kibibytes).
  3. Upon receiving a message from a client, inspect the message type (first character).
    • If the message type is s, prepare to receive a file from the client with the given name and size.
    • If the message type is d, write the delivered chunk to the file system.
    • Otherwise, terminate gracefully with an error.
  4. In both cases, reply with an acknowledge message in the format a|seqno where
    • a indicates that the message type is acknowledgement.
    • seqno equals (x+1)%2 where x is the sequence number of the message to be acknowledged.
  5. Once the file is received completely, the server should print an indicating message, write the content to the file system, and close the file.
  6. If an existing file with the same name is present in the server directory, the server should print an indicating message and overwrite that file with the new one.
  7. Your server will be tested under constant delay and packet loss. The following Linux command can be used to simulate 15% packet loss and 1100 milliseconds constant delay over the lo interface. File transfer should still succeed after applying the command. To undo the effect use del instead of add.
    sudo tc qdisc add dev lo root netem loss 15% delay 1100ms
    
  8. The server stays running unless a fatal error occurs or a KeyboardInterrupt is received.

Testing

ClientServers | 0 | note.txt | 2000a | 1d | 1 | chunk1a | 0ClientServer

Checklist

Your submitted code should satisfy the following requirements. Failing to satisfy an item will result in partial grade deduction or an assignment failure (depending on the severity).