https://github.com/denis-source/c_server
Simple TCP server written in C
https://github.com/denis-source/c_server
c mqueue multithreading posix tcp
Last synced: 3 months ago
JSON representation
Simple TCP server written in C
- Host: GitHub
- URL: https://github.com/denis-source/c_server
- Owner: Denis-Source
- License: gpl-3.0
- Created: 2024-05-28T22:04:07.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-30T00:15:55.000Z (over 1 year ago)
- Last Synced: 2024-12-28T11:12:09.597Z (about 1 year ago)
- Topics: c, mqueue, multithreading, posix, tcp
- Language: C
- Homepage:
- Size: 883 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple TCP server written in C

> Can be used with `netcat` or `telnet`
## Project Overview:
The project aims to develop a simple chat application that can handle incoming connections, manage client-server communication, and process messages efficiently using multithreading and message queues.
## Key Components:
1. **Server Context**:
- Manages the state of the server, including the key-value table of connections and the buffer of recent messages.
2. **Connection Management**:
- Provides functions for initializing, handling, and closing client connections.
3. **Message Handling**:
- Defines message structures and functions for processing incoming and outgoing messages.
4. **Multithreading**:
- Utilizes pthreads for concurrent execution of tasks, such as listening for incoming connections and handling client requests.
5. **Message Queues**:
- Implements message queues for inter-thread communication, allowing seamless message passing between different components of the server.
## Workflow:
1. **Initialization**:
- The server initializes its context, establishes a message queue for communication, and sets up data structures for connection and message management.
2. **Connection Acceptance**:
- The server listens for incoming connections and accepts them using a listener thread.
3. **Message Handling**
- Incoming messages from clients are processed using message queues.
- Message content is decoded and appropriate actions are taken based on the message type.
4. **Response Generation**:
- Upon receiving messages, the server generates appropriate responses and sends them back to clients or performs necessary actions.
5. **Termination**:
- The server gracefully shuts down, freeing resources and closing connections before exiting.
## Technologies Used:
- **C Programming Language**: Core server logic is implemented in C for low-level control and performance optimization.
- **POSIX Threads (pthreads)**: Multithreading capabilities are leveraged using pthreads for concurrent execution of tasks.
- **Message Queues (POSIX mq)**: Inter-thread communication is facilitated through message queues, enabling seamless message passing between components.
## Target Environment:
- The server application is designed to run in a POSIX-compliant environment, such as Unix-like operating systems (e.g., Linux).