jsocketpp 1.0
A cross-platform C++17 socket library.
Loading...
Searching...
No Matches
jsocketpp: Modern C++17 Cross-Platform Socket Library

Build Status GH Doxygen License: MIT Conan vcpkg

Java-style sockets for modern C++17. Cross-platform, robust, and simple.

logo

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

vcpkg install jsocketpp

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

int main() {
// Start a server with address reuse and 5s accept timeout, auto-bind/listen
ServerSocket server(8080, {}, true, true, 5000);
// (bind() and listen() are called automatically)
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

int main() {
DatagramSocket socket(12345); // Bind to port 12345
socket.bind();
DatagramPacket packet(1024);
socket.read(packet); // Receives data and fills `packet`
// Echo it back to sender
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!