Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kaniteru/simplesocket
Single-header, cross-platform TCP/UDP socket wrapper in c++
https://github.com/kaniteru/simplesocket
cpp cpp98 cross-platform linux poxis single-header socket tcp tcp-client tcp-server tcp-socket udp udp-client udp-server udp-socket unix windows wrapper
Last synced: about 1 month ago
JSON representation
Single-header, cross-platform TCP/UDP socket wrapper in c++
- Host: GitHub
- URL: https://github.com/kaniteru/simplesocket
- Owner: kaniteru
- License: mit
- Created: 2024-08-03T15:06:07.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-16T13:51:34.000Z (about 2 months ago)
- Last Synced: 2024-09-29T23:23:46.178Z (about 2 months ago)
- Topics: cpp, cpp98, cross-platform, linux, poxis, single-header, socket, tcp, tcp-client, tcp-server, tcp-socket, udp, udp-client, udp-server, udp-socket, unix, windows, wrapper
- Language: C++
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SimpleSocket
Easy to use C++ TCP/UDP socket wrapper
## Features
- **Simple Usage**
- **Single Header**
- **Cross-Platform**
- Windows
- Linux
- Unix (macOS)
- ...
- **IPv4 and IPv6 Support**
- **C++98 Standard Support**## Usage
**You can see more example projects [here](https://github.com/kaniteru/SimpleSocket/tree/main/examples).**
```cpp
#include
```
```cpp
kani::SocketInfo info;
info.m_node = "localhost"; // host name or ip address
info.m_service = 1234; // node name or port number
```### TCP Server
```cpp
kani::TcpServerSocketInfo tcpInfo;
info.m_node = "localhost";
info.m_service = 1234;
info.m_backlog = SOMAXCONN;kani::TcpServer server(tcpInfo);
if (!server.is_valid() || server.start() != kani::SS_START_RESULT_SUCCESS) {
return;
}TcpNetClient client;
while (!server.wait_client(&client)) { }
kani::SendMsg msg("hello world!");
server.send_msg(&client, &msg);kani::RecvMsg response;
server.recv_msg(&client, &response);server.stop();
```### TCP Client
```cpp
kani::TcpClient client(info);if (!client.is_valid() || client.start() != kani::SS_START_RESULT_SUCCESS) {
return;
}if (!client.connect()) {
return;
}kani::SendMsg msg("hello world!");
client.send_msg(&msg);kani::RecvMsg response;
client.recv_msg(&response);client.stop();
```### UDP Server
```cpp
kani::UdpServer server(info);if (!server.is_valid() || server.start() != kani::SS_START_RESULT_SUCCESS) {
return;
}NetAddr client;
kani::RecvMsg msg;
server.recv_msg(&client, &msg);kani::SendMsg response("hello world!");
server.send_msg(&client, &response);server.stop();
```### UDP Client
```cpp
kani::UdpClient client(info);if (!client.is_valid() || client.start() != kani::SS_START_RESULT_SUCCESS) {
return;
}kani::SendMsg msg("hello world!");
client.send_msg(&msg);kani::RecvMsg response;
client.recv_msg(&response);client.stop();
```## Todo
- [ ] Add more detailed error types to **eSSMsgStatus**
- [ ] Add more example projects
- [ ] Thread safe TCP/UDP Server interacting with multiple clients## License
Unless otherwise specified in subfolders or files, all files in this repository are distributed under the MIT License.
See [LICENSE.txt](https://github.com/kaniteru/SimpleSocket/blob/main/LICENSE.txt) for more information.