From dcdf4c021795692a65a62ef93f63ee60190dd36d Mon Sep 17 00:00:00 2001
From: acgist <289547414@qq.com>
Date: Sat, 18 Mar 2023 22:59:54 +0800
Subject: [PATCH] [+] c++
---
docs/Deploy.md | 2 +-
taoyao-client-harmony/README.md | 133 ++++++++++++++----
taoyao-client-harmony/hi3518e.xml | 7 +
taoyao-client-harmony/os/.gitignore | 2 +
taoyao-client-harmony/os/README.md | 3 +
taoyao-client-harmony/os/bundle.json | 28 ++++
taoyao-client-harmony/os/bundle.release.json | 30 ++++
taoyao-client-harmony/taoyao/.gitignore | 10 ++
taoyao-client-harmony/taoyao/.gitmodules | 4 +
taoyao-client-harmony/taoyao/CMakeLists.txt | 84 +++++++++++
taoyao-client-harmony/taoyao/README.md | 1 +
.../taoyao/include/AudioPublisher.hpp | 8 ++
.../taoyao/include/MediaClient.hpp | 8 ++
.../taoyao/include/MediaRecorder.hpp | 8 ++
.../taoyao/include/Taoyao.hpp | 72 ++++++++++
.../taoyao/include/VideoPublisher.hpp | 8 ++
taoyao-client-harmony/taoyao/include/main.hpp | 1 +
taoyao-client-harmony/taoyao/src/main.cpp | 10 ++
.../taoyao/src/media/AudioPublisher.cpp | 5 +
.../taoyao/src/media/MediaClient.cpp | 5 +
.../taoyao/src/media/MediaRecorder.cpp | 5 +
.../taoyao/src/media/VideoPublisher.cpp | 5 +
.../taoyao/src/signal/Taoyao.cpp | 84 +++++++++++
.../com/acgist/taoyao/service/Server.java | 48 +++++++
24 files changed, 544 insertions(+), 27 deletions(-)
create mode 100644 taoyao-client-harmony/hi3518e.xml
create mode 100644 taoyao-client-harmony/os/.gitignore
create mode 100644 taoyao-client-harmony/os/README.md
create mode 100644 taoyao-client-harmony/os/bundle.json
create mode 100644 taoyao-client-harmony/os/bundle.release.json
create mode 100644 taoyao-client-harmony/taoyao/.gitignore
create mode 100644 taoyao-client-harmony/taoyao/.gitmodules
create mode 100644 taoyao-client-harmony/taoyao/CMakeLists.txt
create mode 100644 taoyao-client-harmony/taoyao/README.md
create mode 100644 taoyao-client-harmony/taoyao/include/AudioPublisher.hpp
create mode 100644 taoyao-client-harmony/taoyao/include/MediaClient.hpp
create mode 100644 taoyao-client-harmony/taoyao/include/MediaRecorder.hpp
create mode 100644 taoyao-client-harmony/taoyao/include/Taoyao.hpp
create mode 100644 taoyao-client-harmony/taoyao/include/VideoPublisher.hpp
create mode 100644 taoyao-client-harmony/taoyao/include/main.hpp
create mode 100644 taoyao-client-harmony/taoyao/src/main.cpp
create mode 100644 taoyao-client-harmony/taoyao/src/media/AudioPublisher.cpp
create mode 100644 taoyao-client-harmony/taoyao/src/media/MediaClient.cpp
create mode 100644 taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp
create mode 100644 taoyao-client-harmony/taoyao/src/media/VideoPublisher.cpp
create mode 100644 taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp
create mode 100644 taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/service/Server.java
diff --git a/docs/Deploy.md b/docs/Deploy.md
index 1adf485..0ebdaad 100644
--- a/docs/Deploy.md
+++ b/docs/Deploy.md
@@ -9,7 +9,7 @@ pm2 >= 5.2.0
Java >= 17.0.0
Maven >= 3.8.0
gcc/g++ >= 10.2.0
-node version >= v16.19.0
+node version >= v16.18.0
python version >= 3.8.0 with PIP
```
diff --git a/taoyao-client-harmony/README.md b/taoyao-client-harmony/README.md
index d3ea36c..a064fde 100644
--- a/taoyao-client-harmony/README.md
+++ b/taoyao-client-harmony/README.md
@@ -1,15 +1,6 @@
# 鸿蒙终端
-提供嵌入式开发能力
-
-## 学习资料
-
-https://device.harmonyos.com/cn/develop/ide/
-https://device.harmonyos.com/cn/documentation/
-https://www.openharmony.cn/docs/zh-cn/overview/
-https://www.openharmony.cn/docs/zh-cn/device-dev/
-https://docs.openharmony.cn/pages/v3.1/zh-cn/OpenHarmony-Overview_zh.md/
-https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/device-dev-guide.md/
+提供嵌入式开发能力,选择开发板`Hi3518E`。
## C++终端
@@ -17,11 +8,20 @@ https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/device-dev-guide.md/
* [libmediasoupclient文档](https://mediasoup.org/documentation/v3/libmediasoupclient)
* [libmediasoupclient接口](https://mediasoup.org/documentation/v3/libmediasoupclient/api)
-## HarmonyOS && OpenHarmony
+## 学习资料
-使用`OpenHarmony`设备开发
+https://hpm.harmonyos.com/#/cn/home
+https://repo.harmonyos.com/#/cn/home
+https://www.hihope.org/download/download.aspx
+https://device.harmonyos.com/cn/develop/ide/
+https://device.harmonyos.com/cn/documentation/
+https://www.openharmony.cn/docs/zh-cn/overview/
+https://www.openharmony.cn/docs/zh-cn/device-dev/
+https://docs.openharmony.cn/pages/v3.1/zh-cn/OpenHarmony-Overview_zh.md/
+https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/device-dev-guide.md/
+https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/hpm-part/hpm-part-about.md/
-## 环境搭建
+## 环境
```
# Ubuntu
@@ -29,19 +29,100 @@ https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/device-dev-guide.md/
# `Ubuntu`选择版本`20.04.5`,建议选择相同版本,不然很多软件版本需要自己调整。
-# SSH
-sudo apt-get remove openssh-server openssh-client --purge
-sudo apt-get install openssh-server openssh-client
-systemctl restart ssh
-systemctl status ssh
-
# 环境搭建
# https://device.harmonyos.com/cn/docs/documentation/guide/ide-install-windows-ubuntu-0000001194073744
-
-sudo mkdir -p /data/dev
-cd /data/dev
-
-小型系统 Hispark_
-Taurus Hi3516DV
-300
+```
+
+## 源码
+
+```
+# 下载源码
+# https://gitee.com/openharmony/manifest/tree/OpenHarmony-3.2-Release/
+# https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md
+
+repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony-3.2-Release -m chipsets/hispark_aries.xml -g ohos:mini --no-repo-verify
+repo sync -c
+repo forall -c 'git lfs pull'
+
+# Marketplace
+# https://hpm.harmonyos.com/#/cn/solution/@ohos%2Fhispark_aries
+# https://repo.harmonyos.com/#/cn/solution/@opensource%2Fhoperun_hm_door_3518
+# https://gitee.com/openharmony-sig/knowledge_demo_smart_home/blob/master/dev/docs/smart_door_viewer_3518/README.md
+
+sudo apt install nodejs
+sudo apt install npm
+npm config set registry https://repo.huaweicloud.com/repository/npm
+npm install -g @ohos/hpm-cli
+```
+
+## 编译
+
+https://hpm.harmonyos.com/#/cn/home
+https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/hpm-part/hpm-part-about.md/
+
+```
+# 下载依赖
+hpm install
+
+# hpm编译
+hpm dist
+
+# hb编译
+pip3 install build/lite
+# hp增量编译
+hb build
+# hp完整编译
+hb build -f
+
+# build编译
+./build.sh \
+ --ccache \
+ --product-name Hi3518EV300 \
+ --build-target build_kernel \
+ --gn-args linux_kernel_version=\"linux-5.10\"
+```
+
+## 烧录
+
+https://www.hihope.org/download/download.aspx
+
+```
+# out/hispark_aries/ipcamera_hispark_aries
+# device/hisilicon/hispark_aries/sdk_liteos/uboot/out/boot
+
+u-boot-hi3518ev300.bin:fastboot
+OHOS_Image.bin:kernel
+rootfs_jffs2.img:rootfs
+userfs_jffs2.img:userfs
+```
+
+## 配置
+
+串口:`115200`
+
+```
+setenv bootcmd "sf probe 0;sf read 0x40000000 0x100000 0x600000;go 0x40000000";
+setenv bootargs "console=ttyAMA0,115200n8 root=flash fstype=jffs2 rw rootaddr=7M rootsize=8M";
+save;
+reset
+./bin/wpa_supplicant -iwlan0 -c /etc/wpa_supplicant.conf
+```
+
+## 代码目录
+
+```
+applications 应用程序样例,包括camera等
+base 基础软件服务子系统集&硬件服务子系统集
+build 组件化编译、构建和配置脚本
+docs 说明文档
+domains 增强软件服务子系统集
+drivers 驱动子系统
+foundation 系统基础能力子系统集
+kernel 内核子系统
+prebuilts 编译器及工具链子系统
+test 测试子系统
+third_party 开源第三方组件
+utils 常用的工具集
+vendor 厂商提供的软件
+build.py 编译脚本文件
```
diff --git a/taoyao-client-harmony/hi3518e.xml b/taoyao-client-harmony/hi3518e.xml
new file mode 100644
index 0000000..c64171b
--- /dev/null
+++ b/taoyao-client-harmony/hi3518e.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/taoyao-client-harmony/os/.gitignore b/taoyao-client-harmony/os/.gitignore
new file mode 100644
index 0000000..f48ed97
--- /dev/null
+++ b/taoyao-client-harmony/os/.gitignore
@@ -0,0 +1,2 @@
+.vscode/
+ohos_bundles
\ No newline at end of file
diff --git a/taoyao-client-harmony/os/README.md b/taoyao-client-harmony/os/README.md
new file mode 100644
index 0000000..4fcb103
--- /dev/null
+++ b/taoyao-client-harmony/os/README.md
@@ -0,0 +1,3 @@
+# 桃夭鸿蒙系统
+
+https://hpm.harmonyos.com/#/cn/solution/@ohos%2Fhispark_aries
diff --git a/taoyao-client-harmony/os/bundle.json b/taoyao-client-harmony/os/bundle.json
new file mode 100644
index 0000000..5efa293
--- /dev/null
+++ b/taoyao-client-harmony/os/bundle.json
@@ -0,0 +1,28 @@
+{
+ "name": "taoyao",
+ "version": "1.0.0",
+ "license": "https://gitee.com/acgist/taoyao/blob/master/LICENSE",
+ "hompage": "https://gitee.com/acgist/taoyao",
+ "repository": "https://gitee.com/acgist/taoyao.git",
+ "description": "桃夭鸿蒙终端",
+ "publishAs": "distribution",
+ "ohos": {
+ "os": "3.0.0",
+ "board": "hi3518",
+ "kernel": "linux"
+ },
+ "base": {
+ "name": "@ohos/hispark_aries",
+ "version": "3.0.3"
+ },
+ "author": {
+ "url": "https://www.acgist.com",
+ "name": "acgist",
+ "email": "rei@acgist.com"
+ },
+ "dirs": {},
+ "envs": {},
+ "scripts": {},
+ "excludes": [],
+ "dependencies": {}
+}
diff --git a/taoyao-client-harmony/os/bundle.release.json b/taoyao-client-harmony/os/bundle.release.json
new file mode 100644
index 0000000..9bbc670
--- /dev/null
+++ b/taoyao-client-harmony/os/bundle.release.json
@@ -0,0 +1,30 @@
+{
+ "name": "taoyao",
+ "version": "1.0.0",
+ "license": "https://gitee.com/acgist/taoyao/blob/master/LICENSE",
+ "hompage": "https://gitee.com/acgist/taoyao",
+ "repository": "https://gitee.com/acgist/taoyao.git",
+ "description": "桃夭鸿蒙终端",
+ "publishAs": "distribution",
+ "ohos": {
+ "os": "3.0.0",
+ "board": "hi3518",
+ "kernel": "linux"
+ },
+ "base": {
+ "name": "@ohos/hispark_aries",
+ "version": "3.0.3"
+ },
+ "author": {
+ "url": "https://www.acgist.com",
+ "name": "acgist",
+ "email": "rei@acgist.com"
+ },
+ "dirs": {},
+ "envs": {
+ "debug": false
+ },
+ "scripts": {},
+ "excludes": ["applications_sample_camera"],
+ "dependencies": {}
+}
diff --git a/taoyao-client-harmony/taoyao/.gitignore b/taoyao-client-harmony/taoyao/.gitignore
new file mode 100644
index 0000000..99e1bca
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/.gitignore
@@ -0,0 +1,10 @@
+CMakeCache.txt
+
+**/*.so
+**/*.exe
+**/*.lib
+
+.vscode/**
+
+build/**
+openharmony/**
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/.gitmodules b/taoyao-client-harmony/taoyao/.gitmodules
new file mode 100644
index 0000000..92176b2
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/.gitmodules
@@ -0,0 +1,4 @@
+[submodule "googletest"]
+ path = test/lib/googletest
+ url = https://github.com/google/googletest.git
+ branch = master
diff --git a/taoyao-client-harmony/taoyao/CMakeLists.txt b/taoyao-client-harmony/taoyao/CMakeLists.txt
new file mode 100644
index 0000000..fcc9dfb
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/CMakeLists.txt
@@ -0,0 +1,84 @@
+cmake_minimum_required(VERSION 3.2)
+
+#define CMAKE_TEMPLATE_VERSION_MAJOR @CMakeTemplate_VERSION_MAJOR@
+#define CMAKE_TEMPLATE_VERSION_MINOR @CMakeTemplate_VERSION_MINOR@
+#define CMAKE_TEMPLATE_VERSION_PATCH @CMakeTemplate_VERSION_PATCH@
+project(taoyao-client-camera VERSION 1.0.0 LANGUAGES C CXX)
+
+# Debug | Release
+# DCMAKE_BUILD_TYPE=Debug
+set(CMAKE_BUILD_TYPE Debug)
+
+# set(CMAKE_C_COMPILER gcc)
+# set(CMAKE_CXX_COMPILER g++)
+
+# 全局宏定义
+# add_definitions(-DDEBUG)
+
+# 全局编译选项
+# add_compile_options()
+
+# C编译选项
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -O3")
+set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0")
+set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
+
+# C++编译选项
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
+set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
+
+# 输出目录
+set(PROJECT_BINARY_DIR ${PROJECT_SOURCE_DIR}/build)
+
+# 包含源代码
+# add_subdirectory(src)
+# add_subdirectory(test)
+
+file(
+ GLOB SOURCE_FILE
+ "include/*.h"
+ "include/*.hpp"
+ "src/main.cpp"
+ "src/media/*.c"
+ "src/signal/*.c"
+ "src/media/*.cpp"
+ "src/signal/*.cpp"
+)
+
+# -lpthread
+
+add_executable(${PROJECT_NAME} ${SOURCE_FILE})
+
+# message("源码地址:" ${SOURCE_FILE})
+
+# 配置
+# cmake -B build
+# Windows:-G "Unix Makefiles"
+# 安装位置:-DCMAKE_INSTALL_PREFIX=`pwd`/output | --install --prefix
+# 打包位置:-DCPACK_OUTPUT_FILE_PREFIX=`pwd`/output
+
+# 编译
+# cmake --build build
+
+# 安装
+# cd build && make install && cd -
+
+# install(
+# TARGETS taoyao
+# RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+# LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+# ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+# )
+
+# 打包
+# cd build && cpack && cd -
+
+# include(CPack)
+# set(CPACK_GENERATOR "ZIP")
+# set(CPACK_SET_DESTDIR ON)
+# set(CPACK_INSTALL_PREFIX "")
+# set(CPACK_PACKAGE_NAME "taoyao")
+# set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
diff --git a/taoyao-client-harmony/taoyao/README.md b/taoyao-client-harmony/taoyao/README.md
new file mode 100644
index 0000000..deb89d5
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/README.md
@@ -0,0 +1 @@
+# 桃夭鸿蒙终端
diff --git a/taoyao-client-harmony/taoyao/include/AudioPublisher.hpp b/taoyao-client-harmony/taoyao/include/AudioPublisher.hpp
new file mode 100644
index 0000000..90b3fbf
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/include/AudioPublisher.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+/**
+ * 音频推送器
+ */
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/include/MediaClient.hpp b/taoyao-client-harmony/taoyao/include/MediaClient.hpp
new file mode 100644
index 0000000..f7b3e96
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/include/MediaClient.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+/**
+ * 媒体终端
+ */
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/include/MediaRecorder.hpp b/taoyao-client-harmony/taoyao/include/MediaRecorder.hpp
new file mode 100644
index 0000000..07b7629
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/include/MediaRecorder.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+/**
+ * 媒体录制
+ */
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/include/Taoyao.hpp b/taoyao-client-harmony/taoyao/include/Taoyao.hpp
new file mode 100644
index 0000000..6c56b95
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/include/Taoyao.hpp
@@ -0,0 +1,72 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#define BUFFER_SIZE 8092
+
+namespace acgist {
+
+/**
+ * 信令
+ */
+class Taoyao {
+private:
+ // 端口
+ int port;
+ // 地址
+ std::string address;
+ // 通道
+ int socketChannel;
+ // 接收线程
+ std::thread acceptThread;
+ // 超时
+ struct timeval timeout;
+ // 地址
+ struct sockaddr_in serverAddress;
+public:
+ /**
+ * @param port 端口
+ * @param address 地址
+ * @param timeout 超时
+ */
+ Taoyao(int port, std::string address, int timeout);
+ /**
+ *
+ */
+ virtual ~Taoyao();
+private:
+ /**
+ * 接收消息
+ */
+ void acceptSignal();
+public:
+ /**
+ * 连接信令
+ */
+ void connectSignal();
+ /**
+ * 推送消息
+ */
+ void push(std::string message);
+ /**
+ * 请求消息
+ */
+ void request(std::string message);
+ /**
+ * 关闭信令
+ */
+ void closeSignal();
+};
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/include/VideoPublisher.hpp b/taoyao-client-harmony/taoyao/include/VideoPublisher.hpp
new file mode 100644
index 0000000..c41be2f
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/include/VideoPublisher.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+/**
+ * 视频推送器
+ */
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/include/main.hpp b/taoyao-client-harmony/taoyao/include/main.hpp
new file mode 100644
index 0000000..6f70f09
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/include/main.hpp
@@ -0,0 +1 @@
+#pragma once
diff --git a/taoyao-client-harmony/taoyao/src/main.cpp b/taoyao-client-harmony/taoyao/src/main.cpp
new file mode 100644
index 0000000..4c11003
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/src/main.cpp
@@ -0,0 +1,10 @@
+#include
+#include "../include/main.hpp"
+
+using std::cout;
+using std::endl;
+
+int main(const int argc, const char **argv) {
+ cout << "测试" << endl;
+ return 0;
+}
diff --git a/taoyao-client-harmony/taoyao/src/media/AudioPublisher.cpp b/taoyao-client-harmony/taoyao/src/media/AudioPublisher.cpp
new file mode 100644
index 0000000..68ab873
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/src/media/AudioPublisher.cpp
@@ -0,0 +1,5 @@
+#include "../../include/AudioPublisher.hpp"
+
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/src/media/MediaClient.cpp b/taoyao-client-harmony/taoyao/src/media/MediaClient.cpp
new file mode 100644
index 0000000..8a4fc03
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/src/media/MediaClient.cpp
@@ -0,0 +1,5 @@
+#include "../../include/MediaClient.hpp"
+
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp b/taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp
new file mode 100644
index 0000000..81ef505
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp
@@ -0,0 +1,5 @@
+#include "../../include/MediaRecorder.hpp"
+
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/src/media/VideoPublisher.cpp b/taoyao-client-harmony/taoyao/src/media/VideoPublisher.cpp
new file mode 100644
index 0000000..b806c48
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/src/media/VideoPublisher.cpp
@@ -0,0 +1,5 @@
+#include "../../include/VideoPublisher.hpp"
+
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp b/taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp
new file mode 100644
index 0000000..2996519
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp
@@ -0,0 +1,84 @@
+#include "../../include/Taoyao.hpp"
+
+namespace acgist {
+
+Taoyao::Taoyao(int port, std::string address, int timeout = 5) {
+ this->port = port;
+ this->address = address;
+ this->socketChannel = 0;
+ this->timeout = {timeout, 0};
+ memset(&this->serverAddress, 0, sizeof(this->serverAddress));
+ this->serverAddress.sin_family = AF_INET;
+ this->serverAddress.sin_port = htons(this->port);
+ this->serverAddress.sin_addr.s_addr = inet_addr(this->address.c_str());
+ // 接收线程
+ this->acceptThread = std::thread(&acgist::Taoyao::acceptSignal, this);
+}
+
+Taoyao::~Taoyao() {
+}
+
+void Taoyao::acceptSignal() {
+ int status;
+ char recvbuf[BUFFER_SIZE];
+ while(true) {
+ if(this->socketChannel == 0) {
+ this->connectSignal();
+ continue;
+ }
+ /**
+ * 0 - 服务断开
+ * -1 - 网络故障:如果设置超时也会出现
+ */
+ status = recv(this->socketChannel, recvbuf, sizeof(recvbuf), 0);
+ if(status == 0) {
+ this->connectSignal();
+ continue;
+ }
+ std::cout << "接收消息:" << status << " - " << recvbuf << std::endl;
+ memset(recvbuf, 0, sizeof(recvbuf));
+ }
+}
+
+void Taoyao::connectSignal() {
+ this->closeSignal();
+ this->socketChannel = socket(AF_INET, SOCK_STREAM, 0);
+ setsockopt(this->socketChannel, SOL_SOCKET, SO_SNDTIMEO, &this->timeout, sizeof(this->timeout));
+ setsockopt(this->socketChannel, SOL_SOCKET, SO_RCVTIMEO, &this->timeout, sizeof(this->timeout));
+ if (connect(this->socketChannel, (struct sockaddr *) &this->serverAddress, sizeof(this->serverAddress)) < 0) {
+ std::cout << "连接失败:重试" << std::endl;
+ this->connectSignal();
+ return;
+ }
+ std::cout << "连接成功:" << this->address << ":" << this->port << std::endl;
+}
+
+void Taoyao::push(std::string message) {
+ std::cout << "发送消息:" << message << std::endl;
+ char sendbuf[message.length() + 1];
+ strncpy(sendbuf, message.c_str(), message.length() + 1);
+ send(this->socketChannel, sendbuf, sizeof(sendbuf), 0);
+ memset(sendbuf, 0, sizeof(sendbuf));
+}
+
+void Taoyao::request(std::string message) {
+}
+
+void Taoyao::closeSignal() {
+ if(this->socketChannel != 0) {
+ close(this->socketChannel);
+ this->socketChannel = 0;
+ }
+}
+
+}
+
+int main(int argc, char const *argv[]) {
+ acgist::Taoyao taoyao(9999, "192.168.1.100");
+ taoyao.connectSignal();
+ char sendbuf[BUFFER_SIZE];
+ while (fgets(sendbuf, sizeof(sendbuf), stdin) != NULL) {
+ taoyao.push(sendbuf);
+ }
+ return 0;
+}
diff --git a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/service/Server.java b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/service/Server.java
new file mode 100644
index 0000000..030b2a7
--- /dev/null
+++ b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/service/Server.java
@@ -0,0 +1,48 @@
+package com.acgist.taoyao.service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+import org.junit.jupiter.api.Test;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class Server {
+
+ public static final Executor EXECUTOR = Executors.newCachedThreadPool();
+
+ @Test
+ public void testServer() throws Exception {
+ final ServerSocket server = new ServerSocket(9999);
+ while(!server.isClosed()) {
+ final Socket accept = server.accept();
+ EXECUTOR.execute(() -> {
+ try {
+ this.execute(accept);
+ } catch (IOException e) {
+ log.error("异常", e);
+ }
+ });
+ }
+ server.close();
+ }
+
+ public void execute(Socket accept) throws IOException {
+ final InputStream inputStream = accept.getInputStream();
+ final OutputStream outputStream = accept.getOutputStream();
+ while(!accept.isClosed()) {
+ final byte[] bytes = new byte[1024];
+ final int length = inputStream.read(bytes);
+ log.info("收到消息:{}", new String(bytes, 0, length));
+ outputStream.write(bytes, 0, length);
+ outputStream.flush();
+ }
+ }
+
+}