Code Monkey home page Code Monkey logo

echo-server's Introduction

๐Ÿ“ข 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()
  • 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()
  • 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()
  • 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.

echo-server's People

Contributors

shlomnissan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.