Skip to content

This project implements a TCP socket communication system between a Sender and a Receiver using CRC-16 with Manchester encoding and manual error injection. It simulates how messages are encoded, transmitted, corrupted, and validated in a real-world communication protocol.

Notifications You must be signed in to change notification settings

samiul-islam-siam/CSE-2109-Assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CRC-16 Error Detection with Manchester Encoding & Socket Communication

1. Introduction

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.

2. System Overview

The workflow is:

  1. Sender reads a text message from the user
  2. Converts message to bits
  3. Appends CRC-16 checksum
  4. Manchester encodes the bitstream
  5. Sends encoded frame over TCP
  6. Receiver decodes Manchester
  7. Extracts payload and CRC
  8. Validates CRC
  9. Displays received message and CRC status

The user can manually select error types to test the CRC detection capability.

3. File Descriptions

sender.c

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)

receiver.c

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

crc16.c / crc16.h

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.

bitvec.c / bitvec.h

Utility for bit-level operations:

  • Creating bit vectors
  • Appending bits
  • Packing/unpacking bits to bytes

Used for converting bytes into bitstream and vice versa.

manchester.c / manchester.h

Implements Manchester encoding/decoding:

  • Each bit encoded into two clocked transitions
  • Ensures self-clocking properties
  • Used to mimic real-world physical layer protocols

netutil.c / netutil.h

Safe network I/O:

  • send_all() — guarantees full send
  • recv_all() — guarantees full receive

Ensures reliable transmission even with partial send/recv calls.

Makefile

Builds all components into:

  • sender
  • receiver
    with dependency tracking and a clean target.

4. Error Injection Types

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

5. How to Run

Option 1: Using Makefile

Compile the project:

make

Run the receiver (terminal 1):

./receiver

Run the sender (terminal 2):

./sender

Clean build artifacts:

make clean

Option 2: Manual Compilation (Without Makefile)

Compile 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.c

Run the receiver:

./receiver

Run the sender (in a separate terminal):

./sender

6. Usage Example

Terminal 1 (Receiver)

[Receiver] Listening on port 5050
[Receiver] Connected.

Terminal 2 (Sender)

[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

Terminal 1 (Receiver Output)

==============================================
 RECEIVED FRAME
==============================================
Payload (11 bytes):
  "Hello World"

CRC Check:
  Received CRC : 0x3A2F
  Calculated CRC: 0x1B4C
  --> CRC STATUS: FAIL (Message Corrupted!)
==============================================

7. Testing Features

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.

8. Conclusion

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.

About

This project implements a TCP socket communication system between a Sender and a Receiver using CRC-16 with Manchester encoding and manual error injection. It simulates how messages are encoded, transmitted, corrupted, and validated in a real-world communication protocol.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published