Student Name: Truong Minh Phuong
Student ID: 29697148
Module: Programming Principles(CMP9133)
A C++ client-server application for parsing and analyzing log files in JSON, TXT, and XML formats using multithreading and TCP networking.
✅ Final coursework project for Programming Principles – MSc Computer Science Applied, University of Lincoln.
- 🔌 TCP client-server architecture
- 🧵 Multithreaded server (each client handled in a detached thread)
- 📂 Support for
JSON
,TXT
, andXML
log formats - 🧠 Analysis by:
USER
– Count logs byuser_id
IP
– Count logs byip_address
LOG_LEVEL
– Count logs by level (INFO, WARN, ERROR, etc.)
- 📅 Optional
FROM
andTO
date range filtering - 📤 Client can batch-send multiple logs from a folder
- 🧱 Raw parsing (no XML/JSON parser dependencies except nlohmann JSON)
/
├── client/
│ └── client.cpp # Console-based log sender
├── server/
│ ├── server.cpp # Multithreaded TCP server
│ ├── parser/
│ │ ├── log_parser.hpp # Abstract parser interface
│ │ ├── json_parser.hpp # JSON parser (uses nlohmann)
│ │ ├── txt_parser.hpp # TXT parser (manual)
│ │ ├── xml_parser.hpp # XML parser (manual tag-matching)
│ │ └── lib/nlohmann/ # nlohmann/json.hpp
├── logs/ # Sample log files for testing
├── README.md
└── Makefile # Optional build script
- Prompts for:
- Server IP and port
- Analysis type (
USER
,IP
,LOG_LEVEL
) - Optional
FROM
andTO
dates (YYYY-MM-DD
) - Log folder path
- Sends each file in the folder to the server
- Receives and prints the analysis result per file
- Listens for client connections on TCP port
8080
- For each connection (threaded):
- Parses the header:
TYPE
,FROM
,TO
- Detects log format:
.json
,.txt
, or.xml
- Applies date filtering
- Analyzes content using the appropriate parser
- Returns result to client
- Parses the header:
[
{
"timestamp": "2024-09-30 22:51:48",
"log_level": "INFO",
"message": "Service started",
"user_id": 1234,
"ip_address": "10.0.0.1"
}
]
2024-09-30 22:51:48 | INFO | Service started | UserID: 1234 | IP: 10.0.0.1
<logs>
<log>
<timestamp>2024-09-30 22:51:48</timestamp>
<log_level>INFO</log_level>
<message>Service started</message>
<user_id>1234</user_id>
<ip_address>10.0.0.1</ip_address>
</log>
</logs>
- C++17 compiler
- POSIX-compatible OS (Linux/macOS)
make
(optional)
# Server
g++ -pthread -o server_app server/server.cpp
# Client
g++ client/client.cpp -o client_app
Or use:
make
# Terminal 1
./server
# Terminal 2
./client
- Start
server
- Start
client
, input:
- IP:
127.0.0.1
- Port:
8080
- Type:
LOG_LEVEL
- FROM:
2024-09-01
- TO:
2024-09-30
- Folder:
./logs/client#1
- Result:
- Summary of log counts by user for files within that folder
=== Analysis Result for log_file.xml ===
INFO: 183013
ERROR: 183696
DEBUG: 183354
WARN: 183742
CRITICAL: 182880
=== End of log_file.xml ===
=== Analysis Result for log_file.txt ===
INFO: 183177
CRITICAL: 183468
WARN: 183314
ERROR: 183563
DEBUG: 183477
=== End of log_file.txt ===
=== Analysis Result for log_file.json ===
ERROR: 183519
DEBUG: 183202
INFO: 184210
WARN: 183117
CRITICAL: 183277
=== End of log_file.json ===
Used for JSON parsing in json_parser.hpp
. This is a header-only modern C++ JSON library under the MIT License.
The MIT License (MIT)
Copyright (c) 2013-2024 Niels Lohmann
Permission is hereby granted, free of charge...
See full license in parser/lib/nlohmann/LICENSE.MIT
.
This project demonstrates:
- ✅ Network programming with low-level sockets
- ✅ File parsing and validation across formats
- ✅ Use of abstraction and inheritance (
LogParser
) - ✅ Threading with
std::thread
- ✅ Input validation and error handling