Implementing a reliable transport protocolA Simplified Transport Control Protocol (STCP)Task OverviewThe purpose of this task is to give you an opportunity to build a simplified version of a transport service that provides a reliable streamed delivery service similar to TCP. You will use this service to transfer a file from a sender to a receiver.This protocol, named STCP (Simplified Transport Control Protocol) will support a window based flow-control mechanism, but it will not have congestion control. In addition, unlike TCP, data will only flow from the sender to the receiver (ACKs will flow in the reverse direction). In broad terms the protocol has a setup phase, a data transfer phase, and a shutdown phase. In this task you will only have to write the sender side, the receiver has already been written for you.We believe that the receiver is reasonably robust but it may contain bugs, so don't be surprised if it occasionally crashes if your application isn't working properly.You are only required to implement the protocol based on the specifications described in this document and comments available in the provided source code.STCP SpecificationOn the wire, an STCP packet, which is encapsulated in a UDP packet, uses the same header as TCP defined by the following C structure:typedef struct tcpheader {unsigned short srcPort; // Not used (should always be 0)unsigned short dstPort; // Not used (should always be 0)unsigned int seqNo;unsigned int ackNo;unsigned char dataOffset; // Not used (should always be 5)unsigned char flags;unsigned short windowSize;unsigned short checksum;unsigned short urgentPointer; // Not used (should always be 0)} tcpheader;Within the tcpheader structure the fields have the same meaning as in TCP. A few of the fields are described below:● The only bits in the flags field that will be used in your implementation are the SYN, FIN, RST, and ACK. For convenience, we often refer to a packet that contains a particular flag whose value is 1 by the name of that flag bit. So, we speak of SYN packets, FIN packets, RST packets, and ACK packets. However, a packet may have multiple of these flag bit set (for example, an acknowledgement of an initial SYN packet will have both the SYN and ACK flags set.● The windowSize field specifies, in bytes, the receiver's advertised receive window size. This field is only interesting for packets sent by the receiver.● The seqNo and ackNo fields are as in TCP. As in TCP, the SYN and FIN flags count as one byte each.Your program must be prepared for the situation when the maximum sequence number is reached and the sequence number wraps around (i.e. becomes smaller than its current value.) In addition, just as in TCP the initial sequence number needs to be randomly selected.● The checksum field is used for corruption checking, and is computed using the standard Internet checksum (a function computing this is provided for you).During protocol processing the receiver can be in four possible states: CLOSED, LISTEN,ESTABLISHED and TIME_WAIT. Initially, it is in the CLOSED state 代 写Implementing a reliable transport protocolR and transitions to the LISTENstate. While in the LISTEN state, the receiver waits for a SYN packet to arrive on the specified port number. When it does, it responds with an ACK, and moves to the ESTABLISHED state. After the sender has transmitted all data, it will send a FIN packet to the receiver. Upon receipt of the FIN, the receiver moves to the TIME_WAIT state after sending an ACK. Similar to TCP, it remains in TIME_WAIT for four seconds before re-entering the CLOSED state.The sender can be in five possible states: CLOSED, SYN_SENT, ESTABLISHED, CLOSING and FIN_WAIT. Like the receiver, the sender starts in the CLOSED state. It initiates a connection by sending a SYN packet (to the receiver's UDP port), thus entering the SYN_SENT state.In the common case in which the SYN is correctly acknowledged, the sender enters theESTABLISHED state and starts transmitting packets. When the sending application (sitting aboveSTCP) is finished generating data, it issues a "close" operation to STCP. This causes the sender to enter the CLOSING state. At this point, the sender must still ensure that all buffered data arrives at the receiver reliably, i.e. it must make sure that all data bytes are acknowledged. Upon verification of successful transmission, the sender sends a FIN packet with the appropriate sequence number and enters the FIN_WAIT state. Once the FIN packet is acknowledged, the sender re-enters theCLOSED state.The sender must be able to send multiple DATA packets before receiving the corresponding ACKpacket. Just how much data is allowed to be sent is based on the value specified in the window field of the most recently received ACK. Once the window limit has been reached, the sender is to wait for new ACK packets until enough bytes are acknowledged and the window has opened to permit the sending, and hence receiving of additional data.Any packet, including the SYN or FIN packets, that is not acknowledged after a timeout must beretransmitted. You should continue to retransmit packets forever (or until you receive a permanenterror from the underlying socket). The retransmission time must take into consideration the actualtime when the the oldest unacknowledged packet was sent.(i.e., If some time elapses between when a packet was originally sent and the existence of an ACK is tested, the elapsed time must be deducted from the time to wait.) The timeout period is to be fixed at one second for the first attempt, two seconds for the second attempt, and four seconds for the third and subsequent attempts.If the sender receives three consecutive ACK packets with the same value for ackNo, and a DATA packet with the same seqNo has already been sent to the receiver, it is to immediately resend thecorresponding DATA packet (similar to TCP's "Fast Retransmission"). Before this packet is sent,though, the sender is to process any ACK packets already in the buffer (i.e. it should call thereceiving function waiting for a zero timeout repeatedly until no packet is returned). After the DATA packet is resent, the sender is to wait for the appropriate timeout period (as described above) for a new ACK. No other DATA packets are to be sent until this ACK arrives, including any other packet that may tim WX:codehelp