---
title: "示例"
---

> Documentation Index
> Fetch the complete documentation index at: https://openarkstudio.github.io/arknet/llms.txt
> Use this file to discover all available pages before exploring further.

# 示例

仓库包含小型 C++ 应用，传输协议指南另提供完整的客户端与服务端程序，数据库指南介绍客户端和连接池。
两端使用一致的依赖方案与 TLS 设置。

## 仓库程序

| 程序 | 源码 | 运行 |
| --- | --- | --- |
| TCP 回显服务端 | [echo_server.cpp](https://github.com/OpenArkStudio/arknet/blob/main/examples/echo_server.cpp) | `build/examples/arknet_echo_server` |
| HTTP 回显服务端 | [http_echo_server.cpp](https://github.com/OpenArkStudio/arknet/blob/main/examples/http_echo_server.cpp) | `build/examples/arknet_http_echo_server` |
| IPv6 客户端与服务端 | [ipv6_echo.cpp](https://github.com/OpenArkStudio/arknet/blob/main/examples/ipv6_echo.cpp) | `build/examples/arknet_ipv6_echo` |
| MySQL 客户端 | [mysql_client.cpp](https://github.com/OpenArkStudio/arknet/blob/main/examples/mysql_client.cpp) | `build/examples/arknet_mysql_client` |
| MySQL 连接池 | [mysql_pool.cpp](https://github.com/OpenArkStudio/arknet/blob/main/examples/mysql_pool.cpp) | `build/examples/arknet_mysql_pool` |
| Redis 客户端 | [redis_client.cpp](https://github.com/OpenArkStudio/arknet/blob/main/examples/redis_client.cpp) | `build/examples/arknet_redis_client` |
| Redis 连接池 | [redis_pool.cpp](https://github.com/OpenArkStudio/arknet/blob/main/examples/redis_pool.cpp) | `build/examples/arknet_redis_pool` |

在仓库根目录构建：

```sh
cmake -S . -B build -DARKNET_BUILD_EXAMPLES=ON \
  -DARKNET_USE_BOOST_ASIO=ON -DARKNET_ENABLE_SSL=ON
cmake --build build --parallel 3
```

Visual Studio 添加 `--config Release`，运行 `examples/Release/` 下的 `.exe`。
程序源码说明实际端口与停止方式。
数据库示例通过参数接收服务端地址，通过环境变量接收密码，见
[MySQL](/arknet/zh/features/mysql/usage)与 [Redis](/arknet/zh/features/redis/usage)。

## 协议程序

| 协议 | 服务端 | 客户端 |
| --- | --- | --- |
| TCP | [完整程序](/arknet/zh/features/tcp/server) | [完整程序](/arknet/zh/features/tcp/client) |
| UDP | [完整程序](/arknet/zh/features/udp/server) | [完整程序](/arknet/zh/features/udp/client) |
| WebSocket | [完整程序](/arknet/zh/features/websocket/server) | [完整程序](/arknet/zh/features/websocket/client) |
| HTTP | [完整程序](/arknet/zh/features/http/server) | [完整程序](/arknet/zh/features/http/client) |
| TLS TCP | [完整程序](/arknet/zh/features/tls/server) | [完整程序](/arknet/zh/features/tls/client) |

[HTTPS](/arknet/zh/features/http/configuration)与[WSS](/arknet/zh/features/websocket/configuration)
说明如何调整这些完整程序。安全传输需要 OpenSSL 与 `ARKNET_ENABLE_SSL=ON`；
仓库私钥仅用于本地测试。

性能程序位于 `benchmarks/`，见[测量方法](/arknet/zh/performance/methodology)。

Source: https://openarkstudio.github.io/arknet/zh/examples/index.mdx
