[+] c++
This commit is contained in:
@@ -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 编译脚本文件
|
||||
```
|
||||
|
||||
7
taoyao-client-harmony/hi3518e.xml
Normal file
7
taoyao-client-harmony/hi3518e.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="GB2312" ?>
|
||||
<Partition_Info ProgrammerFile="">
|
||||
<Part Sel="1" PartitionName="fastboot" FlashType="spi" FileSystem="none" Start="0" Length="1M" SelectFile="D:\tmp\openharmony\u-boot-hi3518ev300.bin"/>
|
||||
<Part Sel="1" PartitionName="kernel" FlashType="spi" FileSystem="none" Start="1M" Length="6M" SelectFile="D:\tmp\openharmony\OHOS_Image.bin"/>
|
||||
<Part Sel="1" PartitionName="rootfs" FlashType="spi" FileSystem="none" Start="7M" Length="8M" SelectFile="D:\tmp\openharmony\rootfs_jffs2.img"/>
|
||||
<Part Sel="1" PartitionName="userfs" FlashType="spi" FileSystem="none" Start="15M" Length="1M" SelectFile="D:\tmp\openharmony\userfs_jffs2.img"/>
|
||||
</Partition_Info>
|
||||
2
taoyao-client-harmony/os/.gitignore
vendored
Normal file
2
taoyao-client-harmony/os/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.vscode/
|
||||
ohos_bundles
|
||||
3
taoyao-client-harmony/os/README.md
Normal file
3
taoyao-client-harmony/os/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# 桃夭鸿蒙系统
|
||||
|
||||
https://hpm.harmonyos.com/#/cn/solution/@ohos%2Fhispark_aries
|
||||
28
taoyao-client-harmony/os/bundle.json
Normal file
28
taoyao-client-harmony/os/bundle.json
Normal file
@@ -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": {}
|
||||
}
|
||||
30
taoyao-client-harmony/os/bundle.release.json
Normal file
30
taoyao-client-harmony/os/bundle.release.json
Normal file
@@ -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": {}
|
||||
}
|
||||
10
taoyao-client-harmony/taoyao/.gitignore
vendored
Normal file
10
taoyao-client-harmony/taoyao/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
CMakeCache.txt
|
||||
|
||||
**/*.so
|
||||
**/*.exe
|
||||
**/*.lib
|
||||
|
||||
.vscode/**
|
||||
|
||||
build/**
|
||||
openharmony/**
|
||||
4
taoyao-client-harmony/taoyao/.gitmodules
vendored
Normal file
4
taoyao-client-harmony/taoyao/.gitmodules
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[submodule "googletest"]
|
||||
path = test/lib/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
branch = master
|
||||
84
taoyao-client-harmony/taoyao/CMakeLists.txt
Normal file
84
taoyao-client-harmony/taoyao/CMakeLists.txt
Normal file
@@ -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 <install-path>
|
||||
# 打包位置:-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})
|
||||
1
taoyao-client-harmony/taoyao/README.md
Normal file
1
taoyao-client-harmony/taoyao/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# 桃夭鸿蒙终端
|
||||
8
taoyao-client-harmony/taoyao/include/AudioPublisher.hpp
Normal file
8
taoyao-client-harmony/taoyao/include/AudioPublisher.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 音频推送器
|
||||
*/
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
8
taoyao-client-harmony/taoyao/include/MediaClient.hpp
Normal file
8
taoyao-client-harmony/taoyao/include/MediaClient.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 媒体终端
|
||||
*/
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
8
taoyao-client-harmony/taoyao/include/MediaRecorder.hpp
Normal file
8
taoyao-client-harmony/taoyao/include/MediaRecorder.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 媒体录制
|
||||
*/
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
72
taoyao-client-harmony/taoyao/include/Taoyao.hpp
Normal file
72
taoyao-client-harmony/taoyao/include/Taoyao.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/types.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
#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();
|
||||
};
|
||||
|
||||
}
|
||||
8
taoyao-client-harmony/taoyao/include/VideoPublisher.hpp
Normal file
8
taoyao-client-harmony/taoyao/include/VideoPublisher.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 视频推送器
|
||||
*/
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
1
taoyao-client-harmony/taoyao/include/main.hpp
Normal file
1
taoyao-client-harmony/taoyao/include/main.hpp
Normal file
@@ -0,0 +1 @@
|
||||
#pragma once
|
||||
10
taoyao-client-harmony/taoyao/src/main.cpp
Normal file
10
taoyao-client-harmony/taoyao/src/main.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <iostream>
|
||||
#include "../include/main.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int main(const int argc, const char **argv) {
|
||||
cout << "测试" << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "../../include/AudioPublisher.hpp"
|
||||
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
5
taoyao-client-harmony/taoyao/src/media/MediaClient.cpp
Normal file
5
taoyao-client-harmony/taoyao/src/media/MediaClient.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "../../include/MediaClient.hpp"
|
||||
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
5
taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp
Normal file
5
taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "../../include/MediaRecorder.hpp"
|
||||
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "../../include/VideoPublisher.hpp"
|
||||
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
84
taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp
Normal file
84
taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user