This repository contains an implementation of KTP (KGP Transport Protocol), a reliable transport protocol built on top of UDP. The project was developed as part of the CS39006: Networks Laboratory course and demonstrates key concepts of transport layer reliability, flow control, and windowing mechanisms.
- Reliable Data Transfer: Implements sequence numbering, acknowledgments, and retransmission
- Flow Control: Sliding window protocol with dynamic window size adjustment
- Error Handling: Robust error detection and handling mechanisms
- Socket API: Provides a socket-like API similar to UDP but with reliability guarantees
- Concurrent Connections: Support for multiple simultaneous KTP sockets
- Fixed message size of 512 bytes
- 8-bit sequence numbers (1-255)
- Sender and receiver window management
- Duplicate detection and handling
- In-order delivery with buffering for out-of-order messages
- Timeout-based retransmission mechanism
The implementation consists of three main components:
- Socket Library: Provides the KTP socket API (
ksocket,kbind,ksendto,krecvfrom,kclose) - Initialization Service: Sets up shared memory, semaphores, and threads for KTP protocol management
- User Applications: Sample client/server applications demonstrating file transfer over KTP
- Receiver Thread: Handles incoming messages, acknowledgments, and window updates
- Sender Thread: Manages retransmissions and sending messages from the buffer
- Garbage Collector: Cleans up sockets from terminated processes
make all
Before using any KTP sockets, you must start the initialization service:
./bin/initksocketThis service must remain running while any application uses KTP sockets.
In one terminal:
# Start the sender
./bin/user1 127.0.0.1 8001 127.0.0.1 8002In another terminal:
# Start the receiver
./bin/user2 127.0.0.1 8002 127.0.0.1 8001This will transfer the contents of testfile.txt from the server to the client, which saves it as received_file_port_8001.txt.
int ksocket(int domain, int type, int protocol);Creates a KTP socket. Use SOCK_KTP as the type.
int kbind(int sockfd, const struct sockaddr *src_addr, socklen_t src_addrlen,const struct sockaddr *dest_addr, socklen_t dest_addrlen);Binds a KTP socket with source and destination addresses.
int ksendto(int sockfd, const void *buf, size_t len, int flags,const struct sockaddr *dest_addr, socklen_t dest_addrlen);Sends data over a KTP socket with reliability guarantees.
int krecvfrom(int sockfd, void *buf, size_t len, int flags,struct sockaddr *src_addr, socklen_t *src_addrlen);Receives data from a KTP socket.
int kclose(int sockfd);Closes a KTP socket and cleans up resources.
ENOSPACE: No space available in the buffer or no KTP socket availableENOTBOUND: Destination address doesn't match the bound addressENOMESSAGE: No message available in the receive bufferEBADF: Bad file descriptor or socket not active
- Currently supports IPv4 only
- Fixed message size of 512 bytes
- Sequence numbers limited to 8 bits (1-255)
- Maximum of 10 concurrent KTP sockets by default
This project is for educational purposes as part of CS39006: Computer Networks Laboratory.