https://github.com/shuai132/socketpp
a lightweight C++ TCP socket library powered by epoll/kqueue, for study.
https://github.com/shuai132/socketpp
epoll kqueue socket tcp tcp-client tcp-server tcp-socket
Last synced: 2 months ago
JSON representation
a lightweight C++ TCP socket library powered by epoll/kqueue, for study.
- Host: GitHub
- URL: https://github.com/shuai132/socketpp
- Owner: shuai132
- Created: 2019-07-09T12:26:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-15T07:02:53.000Z (over 2 years ago)
- Last Synced: 2025-03-21T02:51:14.858Z (3 months ago)
- Topics: epoll, kqueue, socket, tcp, tcp-client, tcp-server, tcp-socket
- Language: C++
- Homepage:
- Size: 35.2 KB
- Stars: 24
- Watchers: 2
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## DEPRECATED. Please use [asio_net](https://github.com/shuai132/asio_net) instead
# Socket++
[](https://www.travis-ci.org/shuai132/SocketPP)
a lightweight C++ TCP socket library, powered by epoll on Linux platform and kqueue on macOS/Unix.
## Features:
* High performance and high concurrenc benefit from epoll/kqueue
* Support send queue with thread safe
* Automatic memory management and ensure performance by c++ move semantics
* Multi-instance support
* Multiplatform support, Linux/macOS and most Unix-like OS.## Requirements:
* C++11## Build:
```bash
mkdir build && cd build && cmake .. && make
```## Usage:
* simple echo server
```cpp
#include "SocketPP.h"using namespace SocketPP;
int main() {
const int port = 6000;
TCPServer server(port);
server.setRecvHandle([&] (const Message& message) {
server.send(message);
});
return server.loop();
}
```
and then use nc tools, or run client example:
```bash
nc localhost 6000
```
or
```cpp
#include "SocketPP.h"using namespace SocketPP;
int main() {
const int port = 6000;
TCPClient client("127.0.0.1", port);
client.setConnHandle([&] (const TCPStream& stream) {
client.send("hello");
});
client.setRecvHandle([&] (const Message& message) {
printf("on receive: msg:%s", message.rawMsg.toString().c_str());
});
return client.loop();
}
```