{"id":16032710,"url":"https://github.com/threez/net-cpp","last_synced_at":"2025-09-07T22:44:06.812Z","repository":{"id":66444324,"uuid":"2044428","full_name":"threez/net-cpp","owner":"threez","description":"EventMachine like reactor implementation for cpp based on libevent","archived":false,"fork":false,"pushed_at":"2011-07-13T22:25:14.000Z","size":100,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-03T10:38:43.761Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/threez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-07-13T21:45:05.000Z","updated_at":"2022-03-24T02:40:34.000Z","dependencies_parsed_at":"2023-02-20T04:15:43.515Z","dependency_job_id":null,"html_url":"https://github.com/threez/net-cpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/threez/net-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threez%2Fnet-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threez%2Fnet-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threez%2Fnet-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threez%2Fnet-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/threez","download_url":"https://codeload.github.com/threez/net-cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threez%2Fnet-cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274107990,"owners_count":25223473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-08T21:40:24.441Z","updated_at":"2025-09-07T22:44:06.772Z","avatar_url":"https://github.com/threez.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Net-cpp\n\nThis is a simple library and test on building a EventMachine like interface\nfor implementing servers in C++. The Naming conventions should be familiar.\nThe implementation uses the very known libevent for implementing the reactor.\n\n## Echo server sample\n\nHere is a simple Application starting an Echo Server on port 9002.\n\n    #include \"net.h\"\n\n    class EchoConnection : public Net::Connection {\n    public:\n      void receivedData(const char * data, int length) {\n        if (strcmp(data, \"exit\\r\\n\") == 0) {\n          closeConnection();\n        } else {\n          sendData(data, length);\n        }\n      }\n    };\n\n    int main (int argc, char * const argv[]) {\n      Net::Server\u003cEchoConnection\u003e echoServer;\n      try {\n        Net::init();\n        Net::startServer(\"0.0.0.0\", 9002, \u0026echoServer);\n        Net::run();\n        return 0;\n      } catch (Net::Exception* ex) {\n        perror(ex-\u003ewhat()); // print network errors\n        return 1;\n      }\n    }\n    \n## HTTP server sample\n\nThis is another sample application implementing an http server:\n\n    #include \"net.h\"\n    const char * response = \"HTTP/1.0 200 OK\\r\\nServer: SimpleHTTP\\r\\nHost: localhost\\r\\nContent-Length: 4\\r\\nContent-Type: text/html\\r\\n\\r\\nTest\";\n    const int responseSize = strlen(response);\n\n    class HTTPConnection : public Net::Connection {\n    public:\n      void receivedData(const char * data, int length) {\n        sendData(response, responseSize);\n        closeConnection();\n      }\n    };\n\n    int main (int argc, char * const argv[]) {\n      Net::Server\u003cHTTPConnection\u003e httpServer;\n      try {\n        Net::init();\n        Net::startServer(\"0.0.0.0\", 9292, \u0026httpServer);\n        Net::run();\n        return 0;\n      } catch (Net::Exception* ex) {\n        perror(ex-\u003ewhat()); // print network errors\n        return 1;\n      }\n    }\n\n## Running more servers\n\nBoth Servers can easily run at the same time:\n\n    #include \"net.h\"\n\n    class EchoConnection : public Net::Connection {\n    public:\n      void receivedData(const char * data, int length) {\n        if (strcmp(data, \"exit\\r\\n\") == 0) {\n          closeConnection();\n        } else {\n          sendData(data, length);\n        }\n      }\n    };\n\n    const char * response = \"HTTP/1.0 200 OK\\r\\nServer: SimpleHTTP\\r\\nHost: localhost\\r\\nContent-Length: 4\\r\\nContent-Type: text/html\\r\\n\\r\\nTest\";\n    const int responseSize = strlen(response);\n\n    class HTTPConnection : public Net::Connection {\n    public:\n      void receivedData(const char * data, int length) {\n        sendData(response, responseSize);\n        closeConnection();\n      }\n    };\n\n    int main (int argc, char * const argv[]) {\n      Net::Server\u003cEchoConnection\u003e echoServer;\n      Net::Server\u003cHTTPConnection\u003e httpServer;\n      try {\n        Net::init();\n        Net::startServer(\"0.0.0.0\", 9002, \u0026echoServer);\n        Net::startServer(\"0.0.0.0\", 9292, \u0026httpServer);\n        Net::run();\n        return 0;\n      } catch (Net::Exception* ex) {\n        perror(ex-\u003ewhat()); // print network errors\n        return 1;\n      }\n    }\n\n# Trying out\n\nSimply install libevent, example for Mac OS X:\n\n    brew install libevent\n    \nAnd then compile using the Makefile\n\n    make\n\nStart the server using:\n\n    ./net-cpp-test\n    \nAnd connect using a telnet client or curl:\n\n    telnet localhost 9002\n    curl http://localhost:9292/\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthreez%2Fnet-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthreez%2Fnet-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthreez%2Fnet-cpp/lists"}