simple_stream_server is a simple TCP server written in C that accepts client connections, stores received data in a file, and returns the full content of this file to the client.
Is supports multiple simultaneous connections using threads. Each incoming connection is handled by a separate thread, ensuring parallel processing of client requests.
It can run either in the foreground or as a daemon, allowing it to execute in the background.
This application is designed to be used as an example of a External Package to be integrated into Buildroot and configured to start automatically using BusyBox init.
simple_stream_server.c: Main server source code.thread_list.c/h: Manages the linked list of active threads.connection_handler.c/h: Handles client connections in separate threads.server_utils.c/h: Contains helper functions for managing the server.Makefile: Script to compile the project.start-stop: Startup script compatible with BusyBox init.README.md: This documentation file.
- Clients can connect using
netcat (nc)ortelnet. - The server stores received messages and sends back the entire content of the file.
- The server can run in normal mode or as a background daemon.
-
The server supports multiple simultaneous connections.
-
Each connection spawns a new thread to handle the interaction.
-
A linked list is used to manage active threads.
-
Threads are properly joined using
pthread_join()(no detached threads).
-
A mutex (pthread_mutex_t********) ensures that data written by different clients does not intermix.
-
Example:
- If one client writes
12345678and another writesabcdefg, the file will always contain ordered entries like: 12345678 abcdefg
- If one client writes
-
It will not result in interleaved data like
123abc456defg.
-
The server catches termination signals (SIGTERM, SIGINT).
-
When exiting, it requests all threads to terminate and waits for their completion.
This package is integrated as as external package into buildroot_external_example and can be selected in menuconfig.
When included in a Buildroot-based system, the following steps are automatically handled:
✅ Cloning this repository.
✅ Compiling simple_stream_server.
✅ Installing the executable in /usr/bin/.
✅ Installing the startup script (start-stop) in /etc/init.d/, so the server starts on boot.
If you want to compile and execute this application as a standalone, do the following:
-
Clone the repository:
git clone https://github.com/moschiel/simple_stream_server.git cd simple_stream_server -
Compile the project using the provided
Makefile:make
This will generate an executable called
simple_stream_server.
Run the server with or without daemon mode:
-
Normal mode:
./simple_stream_server
-
Daemon mode:
./simple_stream_server -d
By default, the server listens on port `9000
To test the server, use netcat (nc) or telnet as a client to send data and verify the response.
In one terminal, start the server:
./simple_stream_serverOpen another terminal and use netcat (nc) to connect to the server:
nc localhost 9000Type a message and press Enter. For example:
Hello, Server!
The server will store this text in the file and send it back. 📩
After sending the data, the server will respond with the full content of the stored file. If you send multiple messages, you will see all of them concatenated.
$ nc localhost 9000
Hello, Server! # <- Client sending
Hello, Server! # <- Server returns the current file content
$ nc localhost 9000
Another message # <- Client sends a new message
Hello, Server! # <- Server returns the stored history
Another message
If running outside Buildroot, you can manually configure the server to start at boot just like Buildroot does using the included start-stop script.
-
Move the server executable to
/usr/bin/(so it can be executed from any directory)::sudo cp simple_stream_server /usr/bin/ sudo chmod +x /usr/bin/simple_stream_server
-
Move the
start-stopscript to/etc/init.d/and rename toS99simple_stream_server(so it runs at boot):sudo cp start-stop /etc/init.d/S99simple_stream_server sudo chmod +x /etc/init.d/S99simple_stream_server
BusyBox init uses the beginnig of the file name (SXX) to identify startup priority of the init.d script.
A lower number starts earlier; a higher number starts later.
That's why it starts with S99, where S means start and 99 indicates it is probably the last one to be executed.
Note: These steps manually replicate what Buildroot does automatically when the package is installed (buildroot_external_example). If using buildroot_external_example, you do not need to do this manually—the system will handle it during the build process.
📌 Summary:
- The server stores all received messages and returns the full file content at the end of each interaction.
- Whenever a client connects, it receives the complete stored history.
- Integrated with Buildroot in the repository buildroot_external_example, where it is automatically installed and configured.
- Can be manually installed and set to start on boot outside Buildroot.