Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ideawu/sim
Simple C++ network server framework
https://github.com/ideawu/sim
Last synced: 18 days ago
JSON representation
Simple C++ network server framework
- Host: GitHub
- URL: https://github.com/ideawu/sim
- Owner: ideawu
- License: bsd-3-clause
- Created: 2015-04-30T01:32:15.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-04-24T13:09:35.000Z (over 4 years ago)
- Last Synced: 2024-10-11T23:14:51.955Z (about 1 month ago)
- Language: C++
- Homepage:
- Size: 148 KB
- Stars: 350
- Watchers: 51
- Forks: 110
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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;
}