Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bluecannonball/polynet
A simple, cross-platform networking abstraction for C++.
https://github.com/bluecannonball/polynet
cpp cross-platform internet network networking tcp udp
Last synced: 9 days ago
JSON representation
A simple, cross-platform networking abstraction for C++.
- Host: GitHub
- URL: https://github.com/bluecannonball/polynet
- Owner: BlueCannonBall
- License: mpl-2.0
- Created: 2022-01-20T02:10:52.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-17T05:04:02.000Z (3 months ago)
- Last Synced: 2024-08-17T20:33:29.609Z (3 months ago)
- Topics: cpp, cross-platform, internet, network, networking, tcp, udp
- Language: C++
- Homepage:
- Size: 218 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Polynet
Polynet is a simple, cross-platform networking abstraction for C++.## Usage
Polynet is designed to be similar to Berkeley sockets while using C++ features such as objects, methods, inheritance, and templates. Polynet supports TCP and UDP.### Quick Examples
```cpp
pn::init();// Creating a TCP server
pn::tcp::Server server;
if (server.bind("0.0.0.0", 8000) == PN_ERROR) {
std::cerr << "Error: " << pn::universal_strerror() << std::endl;
exit(EXIT_FAILURE);
}// Accepting connections (this blocks until an error occurs or the callback returns false)
if (server.listen(/* Accept callback */) == PN_ERROR) {
std::cerr << "Error: " << pn::universal_strerror() << std::endl;
exit(EXIT_FAILURE);
}// Creating a TCP client
pn::tcp::Client client;
if (client.connect("localhost", 8000) == PN_ERROR) {
std::cerr << "Error: " << pn::universal_strerror() << std::endl;
exit(EXIT_FAILURE);
}pn::quit();
```
See `polynet.hpp` and `smart_sockets.hpp` to check out more ways to use Polynet. Since the secure examples are a bit longer, they can be found in the examples directory.### What are `pn::UniqueSocket`, `pn::SharedSocket`, and `pn::WeakSocket`?
These 3 class templates are like `std::unique_ptr`, `std::shared_ptr`, and `std::weak_ptr`, except they work with sockets rather than pointers. They ensure that sockets they own are automatically closed once they are no longer needed.