![]() |
jsocketpp 1.0
A cross-platform C++20 socket library.
|
A C++ socket library providing Java-style networking interfaces. More...
Namespaces | |
namespace | internal |
Implementation-only utilities and platform abstractions for jsocketpp. | |
namespace | net |
Endianness utilities for network byte order conversion. |
Classes | |
struct | BufferView |
Represents a raw writable memory region for scatter/gather I/O. More... | |
class | DatagramPacket |
Represents a UDP datagram packet, encapsulating both payload and addressing information. More... | |
class | DatagramSocket |
Cross-platform UDP socket class with Java-style interface. More... | |
class | MulticastSocket |
Cross-platform multicast UDP socket class (IPv4/IPv6). More... | |
class | ServerSocket |
TCP server socket abstraction for cross-platform C++ networking. More... | |
class | Socket |
TCP client connection abstraction (Java-like interface). More... | |
class | SocketException |
Represents socket-related errors in the jsocketpp library. More... | |
class | SocketInitializer |
Helper class to initialize and cleanup sockets (RAII). More... | |
class | SocketTimeoutException |
Exception class for socket operations that time out. More... | |
class | UnixSocket |
Cross-platform abstraction for Unix domain sockets. More... |
Typedefs | |
typedef int | SOCKET |
typedef sockaddr_un | SOCKADDR_UN |
using | Port = std::uint16_t |
Type alias representing a TCP or UDP port number (1–65535). |
Enumerations | |
enum class | ShutdownMode { Read , Write , Both } |
Enum for socket shutdown modes. More... |
Functions | |
int | InitSockets () |
int | CleanupSockets () |
int | GetSocketError () |
int | CloseSocket (SOCKET fd) |
const char * | inet_ntop_aux (int af, const void *src, char *dst, socklen_t size) |
int | ioctlsocket (const SOCKET fd, const long cmd, u_long *argp) |
std::vector< std::string > | getHostAddr () |
Get all local network interface addresses as strings. | |
std::string | SocketErrorMessage (int error, bool gaiStrerror=false) |
Returns a human-readable error message for a socket error code. | |
std::string | SocketErrorMessageWrap (int error, bool gaiStrerror=false) |
Returns a human-readable error message for a socket error code, with exception safety. | |
bool | isIPv4MappedIPv6 (const sockaddr_in6 *addr6) |
Checks if a given sockaddr_in6 represents an IPv4-mapped IPv6 address. | |
sockaddr_in | convertIPv4MappedIPv6ToIPv4 (const sockaddr_in6 &addr6) |
Converts an IPv4-mapped IPv6 address to a pure IPv4 sockaddr_in. | |
template<> | |
std::string | DatagramSocket::read< std::string > () |
Read a string from the socket (connected UDP). | |
template<> | |
std::string | DatagramSocket::recvFrom< std::string > (std::string *senderAddr, Port *senderPort) |
Receive a datagram as a string (connectionless). |
Variables | |
constexpr SOCKET | INVALID_SOCKET = -1 |
constexpr SOCKET | SOCKET_ERROR = -1 |
constexpr std::size_t | DefaultBufferSize = 4096 |
Default internal buffer size (in bytes) for TCP socket read operations. |
A C++ socket library providing Java-style networking interfaces.
The jsocketpp namespace contains classes and utilities for network programming with an API design inspired by Java's networking classes. It provides:
Core Socket Classes:
Features:
Design Philosophy:
typedef sockaddr_un jsocketpp::SOCKADDR_UN |
typedef int jsocketpp::SOCKET |
|
strong |
|
inlineconstexpr |
|
inline |
|
inline |
Read a string from the socket (connected UDP).
SocketException | on error. |
|
inline |
Receive a datagram as a string (connectionless).
senderAddr | [out] String to store sender's address. |
senderPort | [out] Variable to store sender's port. |
SocketException | on error. |
std::vector< std::string > jsocketpp::getHostAddr | ( | ) |
Get all local network interface addresses as strings.
|
inline |
const char * jsocketpp::inet_ntop_aux | ( | int | af, |
const void * | src, | ||
char * | dst, | ||
socklen_t | size ) |
Redefine because not available on Windows XP http://stackoverflow.com/questions/13731243/what-is-the-windows-xp-equivalent-of-inet-pton-or-inetpton
|
inlineconstexpr |
|
inline |
std::string jsocketpp::SocketErrorMessage | ( | int | error, |
bool | gaiStrerror = false ) |
Returns a human-readable error message for a socket error code.
On Windows:
error | The error code (platform-specific). |
gaiStrerror | If true, interpret error as a getaddrinfo error code (POSIX only). |
std::string jsocketpp::SocketErrorMessageWrap | ( | int | error, |
bool | gaiStrerror = false ) |
Returns a human-readable error message for a socket error code, with exception safety.
Like SocketErrorMessage, but guarantees not to throw exceptions (e.g., for use in destructors). If an error occurs while generating the message, returns a fallback string (on Windows, uses strerror for Winsock codes).
error | The error code (platform-specific). |
gaiStrerror | If true, interpret error as a getaddrinfo error code (POSIX only). |
|
constexpr |
|
constexpr |