Coder Social home page Coder Social logo

nettyplusplus's Introduction

netty++

C++ port of http://netty.io/

Here's an example - an Echo Server, that uses the netty++ library:

#include "Server.h"
#include <vector>

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <getopt.h>

void signal_cleanup(int);
void signal_pipe(int);

// Derive ChannelHandler that simply echo's to the screen what was received.
class EchoChannelHandler : public ChannelHandler {
public:
	EchoChannelHandler() { }

	virtual ~EchoChannelHandler() { }

	void onMessageReceived(Channel &channel) {
		std::string str = channel.readLine();
		channel.write(str + "\r\n");
	}

};

int main(int argc, char **argv) {
    int opt_port = 33000;
    int opt_workers = 4;

    // signal catcher first!
    (void) signal(SIGINT,signal_cleanup);
    (void) signal(SIGPIPE,signal_pipe);

    EchoChannelHandler *ech = new EchoChannelHandler();

    // listen on opt_port, with opt_workers to process the Echo Channel Handler
    Server server(opt_port, opt_workers, ech);

    server.run();

    // or server.start() for threaded run.

    return 0;
}

void signal_cleanup(int sig) {
    std::cout << "sigint received.  going down." << std::endl;
    exit(sig);
}

void signal_pipe(int sig) {
    std::cout << "sigpipe caught.  doing nothing!" << std::endl;
}

nettyplusplus's People

Watchers

 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.