Giter Club home page Giter Club logo

simpleserver's Introduction

SimpleServer

This repository contains my implementation of a simple TCP/IP server in C++. I started fiddling with this to learn more about UNIX network programming.

See the initial blog post or its successor for additional information and comments.

How do I use the API?

The sources are meant to become an API when they grow up. At present there are two server implementations:

  • qotd.cc contains a Quote of the Day service implementation
  • echo.cc contains an echo service implementation

What's cool about it?

Good question. I wanted to encapsulate the C API for socket programming and make it more modern. So far, I did not really succeed, I guess. There is one cool thing at the moment: Requests are handled by specifying an arbitrary function object (yay, C++11). This function is then called asynchronously (yay, C++11 again!) whenever a new client is accepted. You can then send stuff to the client or whatever...

How do I run my own QOTD server?

That at least I may answer! After cloning this repository, please run the following commands:

$ mkdir build
$ cd build
$ cmake ../
$ make
$ ./qotd ../Quotes.txt

You can exit the server with CTRL+C. You can connect to your server like this:

$ nc localhost 1041

Why is the QOTD server not running under port 17?

Because most Linux distributions disallow opening ports below 1024 without root access or at least configuration changes. While I think that I am a trustworthy person, I do not presume that you want to compile this as root...

Thus, the QOTD server runs under port 1041, which is 1024+17 and hence quite clever.

How do I run my own echo server?

$ mkdir build
$ cd build
$ cmake ../
$ make
$ ./echo

Note that the server runs under port 1031, which is 1024+7 and hence quite clever as well (see the answer to the previous question).

Acknowledgements

Thanks to Uri London for very useful suggestions that helped improve the code.

Licence

The code is released under an MIT licence.

simpleserver's People

Contributors

pseudomanifold avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.