https://github.com/shlomnissan/echo-server
📢 A simple TCP echo server with different methods for sync multiplexing
https://github.com/shlomnissan/echo-server
bsd-sockets multiplexing tcp tcp-server
Last synced: 3 months ago
JSON representation
📢 A simple TCP echo server with different methods for sync multiplexing
- Host: GitHub
- URL: https://github.com/shlomnissan/echo-server
- Owner: shlomnissan
- Created: 2023-01-28T00:04:33.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-01T15:58:27.000Z (over 2 years ago)
- Last Synced: 2025-01-14T23:05:36.841Z (4 months ago)
- Topics: bsd-sockets, multiplexing, tcp, tcp-server
- Language: C
- Homepage:
- Size: 33.2 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 📢 echo-server
This project is a simple implementation of a TCP echo server using BSD sockets that I put together to explore different methods of synchronous I/O multiplexing in a Linux environment. It allows for the selection of a multiplexing method using an application argument. Available methods are select, poll, and epoll, and each method has performance and cross-platform compatibility trade-offs.
*Note*: this program uses epoll, a Linux kernel system call, so it can only be compiled in a Linux environment.
## Usage
```
echo_server 8080 epoll
```
- `arg[1]` the port you want the server to bind to.
- `arg[2]` the multiplexing method you want to use (select, poll, or epoll).Both arguments are required.
The simplest way to test the server is using `telnet`.
## Synchronous I/O multiplexing methods
| Method | Summary |
| ------------- | ------------- |
| [select()](https://man7.org/linux/man-pages/man2/select.2.html) |
- The primary advantage is portability. BSD sockets and WINSOCK interfaces fully support it.
- It can only monitor up to 1024 file descriptors. Unix man recommends that modern applications use `poll()` or `epoll()`.
- It isn't very efficient. The kernel has to iterate through the max file descriptor value, even when a single file descriptor is watched.
- File descriptor sets are reconstructed on return, so each subsequent call must reinitialize them.
| [poll()](https://man7.org/linux/man-pages/man2/poll.2.html) |
- It improves on the `select()` method, but it's only available in UNIX.
- It stores file descriptors in an array, so it doesn't need to iterate through the max file descriptor value.
- The `poll()` system call separates input and output events, allowing the array to be reused without having to reinitialize it.
- The time complexity of `poll()`, like `select()` is O(n), and it's still a slow solution when a large number of file descriptors is used.
| [epoll()](https://man7.org/linux/man-pages/man7/epoll.7.html) |
- It performs better than `select()` and `poll()`, but it's only available on Linux and not standardized by POSIX.
- The time complexity of `epoll()` is O(1).
- `epoll_wait()` only returns file descriptors ready for IO operations, so there's no need to iterate through the entire set.
- It allows adding and removing file descriptors while waiting.
- It can be used either as an edge-triggered or a level-triggered interface.
## Licence
```
____ __ __
/ __ )___ / /_____ _____ ___ ____ ______/ /__
/ __ / _ \/ __/ __ `/ __ `__ \/ __ `/ ___/ //_/
/ /_/ / __/ /_/ /_/ / / / / / / /_/ / / / ,<
/_____/\___/\__/\__,_/_/ /_/ /_/\__,_/_/ /_/|_|
Copyright (c) 2023 Shlomi Nissan
https://betamark.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```