TCP Client-Server Communication to Identify Matrix Type (Upper/Lower/Diagonal)
Experiment
TCP Client-Server Communication to Identify Matrix Type (Upper/Lower/Diagonal)
Aim
To implement a TCP client-server program where the client sends a randomly generated square matrix to the server, and the server determines its type (upper triangular, lower triangular, or diagonal).
Objective
- To understand structured data transmission over TCP
- To implement client-server communication using sockets in C
- To perform matrix analysis at the server side
Theory
TCP Communication
TCP provides:
- Reliable communication
- Ordered data transfer
- Error detection and retransmission
Matrix Types
Let be a square matrix:
-
Upper Triangular Matrix
All elements below diagonal are zero
๐ -
Lower Triangular Matrix
All elements above diagonal are zero
๐ -
Diagonal Matrix
All non-diagonal elements are zero
๐
Algorithm
Client
-
Input integer
N -
Generate
N x Nmatrix with random values (1–50) - Display matrix
-
Send
Nto server - Send matrix elements
- Receive matrix type
- Display result
Server
- Create socket
- Bind and listen
- Accept connection
-
Receive
N - Receive matrix
- Check matrix type
- Send result to client
- Close connection
๐ป Program
๐น Client Program (C)
๐น Server Program (C)
▶️ Compilation & Execution
Run:
-
Terminal 1 →
./server -
Terminal 2 →
./client
๐ Sample Output
Client
Server
✅ Result
The TCP client-server program successfully transmitted a matrix and correctly identified its type at the server side.
Comments
Post a Comment