Simple C++ network server framework
Switch branches/tags
Nothing to show
Clone or download
Latest commit 6e37151 May 2, 2017
Permalink
Failed to load latest commit information.
api update test.php Jul 18, 2015
src Merge pull request #4 from hexingb/master May 2, 2017
test update README.md May 18, 2015
.gitignore add cpp api client Jun 9, 2015
LICENSE add LICENSE May 10, 2015
Makefile move src/test to test May 5, 2015
README.md update README.md May 18, 2015
build.sh update Apr 30, 2015

README.md

sim

C++ network server framework, nc and telnet friendly.

#demo

#include "sim/sim.h"

class MyHandler : public sim::Handler
{
public:
	virtual sim::HandlerState proc(const sim::Request &req, sim::Response *resp){
		std::string cmd = req.msg.type();
		if(cmd == "ping"){
			resp->msg.add("ok");
			resp->msg.add("pong");
		}else{
			resp->msg.add("ok");
			resp->msg.add(cmd);
		}
		return this->resp();
	}
};

int main(int argc, char **argv){
	const char *ip = "127.0.0.1";
	int port = 8800;
	sim::Server *serv = sim::Server::listen(ip, port);
	if(!serv){
		log_fatal("%s", strerror(errno));
		exit(0);
	}
	log_info("server listen on %s:%d", ip, port);

	MyHandler handler;
	serv->add_handler(&handler);

	serv->loop();
	return 0;
}