Git Product home page Git Product logo

cliserver's Introduction

cliserver

A libevent-based server that handles simple commands from multiple clients. Created while learning to use libevent, this is intended to help alleviate the relative dearth of libevent sample code. See the reasonably-well-commented source code for additional information, and feel free to borrow the macros at the beginning of cliserver.c (though if you think they're useful, credit would be appreciated).

This code has been tested not to leak memory or file descriptors under a variety of conditions using valgrind.

Note that evbuffer_readline() is a potential source of denial of service, as it does an O(n) scan for a newline character each time it is called. One solution would be checking the length of the buffer and dropping the connection if the buffer exceeds some limit (dropping the data is less desirable, as the client is clearly not speaking our protocol anyway). Another (more ideal) solution would be starting the newline search at the end of the existing buffer. The server won't crash with really long lines within the limits of system RAM (tested using lines up to 1GB in length), it just runs slowly.

Clients connect to the server on port 14310, allowing them to run the following commands:

  • echo: Print the command line.
  • help: Print a list of commands and their descriptions.
  • info: Print connection information.
  • quit: Disconnect from the server.
  • kill: Shut down the server.

A sample client interaction:

> help
echo:	Prints the command line.
help:	Prints a list of commands and their descriptions.
info:	Prints connection information.
quit:	Disconnects from the server.
kill:	Shuts down the server.
> info
Client address: ::1
Client port: 60642
> echo This is just a simple test program.
This is just a simple test program.
> quit

Compiling cliserver

Compile the server with make, run it with ./cliserver. Connect to the server using netcat: nc localhost 14310.

You will need libevent 1.x (I'm using 1.4.13 from Ubuntu 10.10), gcc, and GNU make to compile this code. It should, in theory, be easily portable to libevent 2.x.

Copyright

(C)2010 Mike Bourgeous, licensed under 2-clause BSD

cliserver's People

Watchers

 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.