This assignment implements a digital communication system between a Sender and Receiver using:
- CRC-16 (CCITT) for error detection
- Manchester encoding for physical-layer bit representation
- TCP socket communication between processes
- Manual error injection (single-bit, multi-bit, odd-bit, burst errors)
The system simulates how messages are encoded, transmitted, corrupted, and validated in a real communication protocol.
The workflow is:
- Sender reads a text message from the user
- Converts message to bits
- Appends CRC-16 checksum
- Manchester encodes the bitstream
- Sends encoded frame over TCP
- Receiver decodes Manchester
- Extracts payload and CRC
- Validates CRC
- Displays received message and CRC status
The user can manually select error types to test the CRC detection capability.
Handles the entire sender-side logic:
- Reads input message
- Converts text → bits
- Computes CRC-16
- Packs data and performs Manchester encoding
- Allows user to choose error types
- Injects bit errors
- Sends frame over TCP socket
Error types implemented:
- Single-bit error
- Two isolated single-bit errors
- Odd number of bit errors
- Burst errors (8, 17, 22 bits)
Implements the receiver:
- Accepts TCP connections
- Reads Manchester-encoded frames
- Decodes back to raw bits
- Extracts payload + CRC bits
- Recomputes CRC
- Displays:
- Received message (even if corrupted)
- Received CRC vs Calculated CRC
- PASS/FAIL status
Implements CRC-16 CCITT polynomial:
- Polynomial:
x^16 + x^12 + x^5 + 1(0x1021) - Initial value:
0xFFFF
Functions:
crc16_ccitt()— generates CRC for a given byte array.
Utility for bit-level operations:
- Creating bit vectors
- Appending bits
- Packing/unpacking bits to bytes
Used for converting bytes into bitstream and vice versa.
Implements Manchester encoding/decoding:
- Each bit encoded into two clocked transitions
- Ensures self-clocking properties
- Used to mimic real-world physical layer protocols
Safe network I/O:
send_all()— guarantees full sendrecv_all()— guarantees full receive
Ensures reliable transmission even with partial send/recv calls.
Builds all components into:
senderreceiver
with dependency tracking and a clean target.
| Option | Error Type | Description |
|---|---|---|
| 0 | No error | Clean transmission |
| 1 | Single bit | Flips 1 bit (usually detected) |
| 2 | Two isolated bits | Flips 2 bits at different positions |
| 3 | Odd number of bits | Flips 3 bits (detectable by CRC) |
| 4 | Burst 8 | Corrupts 8 consecutive bits |
| 5 | Burst 17 | Corrupts 17 consecutive bits |
| 6 | Burst 22 | Corrupts 22 consecutive bits |
Compile the project:
makeRun the receiver (terminal 1):
./receiverRun the sender (terminal 2):
./senderClean build artifacts:
make cleanCompile all source files and link:
gcc -Wall -Wextra -O2 -o receiver receiver.c crc16.c manchester.c bitvec.c netutil.c
gcc -Wall -Wextra -O2 -o sender sender.c crc16.c manchester.c bitvec.c netutil.cRun the receiver:
./receiverRun the sender (in a separate terminal):
./sender[Receiver] Listening on port 5050
[Receiver] Connected.
[Sender] Connecting to receiver...
[Sender] Connected.
Enter message to send (or 'exit'): Hello World
Choose error type:
0 = No error
1 = Single bit
2 = Two isolated bits
3 = Odd number of bit errors
4 = Burst 8
5 = Burst 17
6 = Burst 22
Enter number: 1
[Sender] Flipped bit 10
[Sender] Injected: Single-bit error
==============================================
RECEIVED FRAME
==============================================
Payload (11 bytes):
"Hello World"
CRC Check:
Received CRC : 0x3A2F
Calculated CRC: 0x1B4C
--> CRC STATUS: FAIL (Message Corrupted!)
==============================================
| Test Case | Description |
|---|---|
| Single-bit error | Flip one bit in encoded message |
| Two isolated errors | Flip two bits far apart |
| Odd number of bit errors | Flip 3 bits |
| Burst errors | Flip 8, 17, or 22 consecutive bits |
CRC-16 correctly detects all errors except extremely rare undetected patterns.
This project simulates a robust digital communication system implementing:
- Data integrity using CRC-16
- Physical-layer encoding via Manchester coding
- Realistic channel errors (bit and burst errors)
- Socket-based sender/receiver architecture
The system demonstrates how digital communication protocols ensure reliability and detect transmission errors effectively.