
Java-style sockets for modern C++17. Cross-platform, robust, and simple.
Overview
jsocketpp is a C++17 cross-platform socket library inspired by the Java networking API. It offers familiar and convenient classes (Socket, ServerSocket, DatagramSocket, MulticastSocket, etc.) to simplify TCP and UDP network programming in C++. The API is designed to be clear, robust, and portable—ideal for modern, high-performance C++ applications.
- Cross-platform: Windows, Linux, macOS
- Supports: TCP, UDP, and UNIX domain sockets
- Easy-to-use Java-style interface
- Modern C++17 features
Features
- Object-oriented socket abstractions (like Java)
- Blocking and non-blocking operations, timeouts
- IPv4 and IPv6 support
- Exception-based error handling
- Internal buffer management
- Optional thread safety
- Support for broadcast and multicast
- Clean RAII resource management
- Unit tested with GoogleTest
Installation
vcpkg
Conan
conan install jsocketpp/[latest]@
Manual
Clone and add to your project:
git clone https://github.com/MangaD/jsocketpp.git
cd jsocketpp
mkdir build && cd build
cmake ..
make
sudo make install
Quick Start
TCP Example
ServerSocket server(8080, {}, true, true, 5000);
Socket client = server.accept();
std::string msg = client.read<std::string>();
client.write("Hello from server!");
}
TCP server socket abstraction for jsocketpp.
TCP client socket abstraction for jsocketpp.
int main()
Definition client.cpp:88
UDP Example
DatagramSocket socket(12345);
socket.bind();
DatagramPacket packet(1024);
socket.read(packet);
socket.write(packet);
}
UDP datagram packet class for jsocketpp.
UDP datagram socket abstraction for jsocketpp.
Java-Inspired API
Java | jsocketpp |
Socket | jsocketpp::Socket |
ServerSocket | jsocketpp::ServerSocket |
DatagramSocket | jsocketpp::DatagramSocket |
DatagramPacket | jsocketpp::DatagramPacket |
MulticastSocket | jsocketpp::MulticastSocket |
Documentation
Building & Testing
cmake --preset=debug
cmake --build --preset=debug
ctest --preset=debug
License
MIT License. See LICENSE.
Contributing
Pull requests are welcome! Please read the contributing guidelines.
Acknowledgements
- Java’s networking API for inspiration
- GoogleTest for unit tests
- All contributors and users!