You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ip-sockets-cpp-lite is a fast, header-only, dependency-free, cross-platform C++ library that makes programming UDP/TCP sockets and working with IPv4/IPv6 addresses as easy as possible.
7
+
It's a fast, header-only, dependency-free, cross-platform C++ library that makes programming UDP/TCP sockets and working with IPv4/IPv6 addresses as easy as possible.
6
8
Forget about endless `getaddrinfo` calls, confusion with `sockaddr_in`/`sockaddr_in6`, and platform-specific workarounds.
This header only library gives you predictable, cross platform blocking I/O udp and tcp sockets with configurable timeouts — the simplest model that works for most real-world applications. Keep it simple, keep it portable! 🎯
52
+
53
+
---
54
+
55
+
## Features 🔧
56
+
57
+
### IP Address Handling (`ip_address.h`)
58
+
- Unified IPv4 and IPv6 support
59
+
- String to binary and back conversion
60
+
- Network prefixes and masks
61
+
- IPv4-over-IPv6 mapping
62
+
- Address + port as a single unit
63
+
- Zero-copy overlay on existing memory buffers
64
+
- Rich constructors from strings, numbers, bytes
65
+
- Flexible parsing of various formats (hex, decimal, dotted)
66
+
67
+
### UDP Sockets (`udp_socket.h`)
68
+
- Unified API and behavior across different OS
69
+
- Client and server modes with IPv4 or IPv6 addresses
70
+
- Blocking I/O with configurable timeouts
71
+
- Сonfigurable comprehensive logging
72
+
- Clear states and error codes across different OS
73
+
74
+
### TCP Sockets (`tcp_socket.h`)
75
+
- Convenient accept with client socket creation
76
+
- Automatic connection management
77
+
- Consistent API with UDP sockets
78
+
79
+
## Requirements 📋
80
+
- C++11 or newer
81
+
- C++ standard library
82
+
- Nothing else!
83
+
25
84
## Quick Start 🏁
26
85
27
-
### 1. Installation
86
+
### 1. Project Integration 🛠️
28
87
29
-
Simply copy three files into your project:
88
+
Option 1 — Simply copy header files what you need into your project:
Spawning a thread to wait for socket I/O is perfectly fine:
322
+
```cpp
323
+
std::thread([&]() {
324
+
while (true) {
325
+
int bytes = server.recvfrom(buffer, sizeof(buffer), client);
326
+
if (bytes > 0) handle_client(client, buffer, bytes);
327
+
}
328
+
}).detach(); // One thread per socket — no problem!
194
329
```
330
+
Modern systems handle thousands of threads easily. **Don't optimize prematurely** — clean code is better than complex async machinery.
195
331
196
-
## Examples 📚
332
+
### ✅ Perfect for 95% of use cases
333
+
- REST API clients
334
+
- IoT devices
335
+
- Game servers
336
+
- Protocol implementations
337
+
- Embedded systems
197
338
198
-
Check out the `examples/` directory for complete working examples:
199
-
-`ip_address.cpp` - all IP address manipulation features
200
-
-`udp_socket.cpp` - UDP client-server interaction
201
-
-`tcp_socket.cpp` - TCP client-server interaction
202
-
-`resolve_host.cpp` - resolving host to ipv4/ipv6 address example
339
+
For the 5% that truly need massive concurrency (10k+ connections), you can still use this library in thread pools or combine it with higher-level async frameworks.
0 commit comments