Hi3861 OpenHarmony嵌入式应用入门--TCP Server

本篇使用的是lwip编写tcp服务端。需要提前准备好一个PARAM_HOTSPOT_SSID宏定义的热点,并且密码为PARAM_HOTSPOT_PSK

LwIP简介

LwIP是什么?

A Lightweight TCP/IP stack 一个轻量级的TCP/IP协议栈

详细介绍请参考LwIP项目官网:lwIP - A Lightweight TCP/IP stack - Summary [Savannah]

LwIP在openharmony上的应用情况

目前,openharmony源码树有两份LwIP:

  1. third_party/lwip
    • 源码形式编译
    • 供liteos-a内核使用
    • 还有一部分代码在kernel/liteos_a中,一起编译
  1. vendor/hisi/hi3861/hi3861/third_party/lwip_sack
    • hi3861-sdk的一部分
    • 静态库形式编译
    • 不可修改配置
    • 可以查看当前配置(vend

LwIP Socket API编程主要是6个步骤:

创建Tcp Server Socket:socket

绑定指定的IP和Port:bind

设置socket为监听状态:listen

阻塞方式等待client连接:accept

阻塞方式receive client的消息:recv

调用send发送消息给TCP Client

修改网络参数

在Hi3861开发板上运行上述四个测试程序之前,需要根据你的无线路由、Linux系统IP修改 net_params.h文件的相关代码:

  • PARAM_HOTSPOT_SSID 修改为你的热点名称
  • PARAM_HOTSPOT_PSK 修改为你的热点密码;

代码编写

修改D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\BUILD.gn文件

# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. import("//build/lite/config/component/lite_component.gni")lite_component("demo") {features = [#"base_00_helloworld:base_helloworld_example",#"base_01_led:base_led_example",#"base_02_loopkey:base_loopkey_example",#"base_03_irqkey:base_irqkey_example",#"base_04_adc:base_adc_example",#"base_05_pwm:base_pwm_example",#"base_06_ssd1306:base_ssd1306_example",#"kernel_01_task:kernel_task_example",#"kernel_02_timer:kernel_timer_example",#"kernel_03_event:kernel_event_example",#"kernel_04_mutex:kernel_mutex_example",#"kernel_05_semaphore_as_mutex:kernel_semaphore_as_mutex_example",#"kernel_06_semaphore_for_sync:kernel_semaphore_for_sync_example",#"kernel_07_semaphore_for_count:kernel_semaphore_for_count_example",#"kernel_08_message_queue:kernel_message_queue_example",#"wifi_09_hotspot:wifi_hotspot_example",#"wifi_10_sta:wifi_sta_example","tcp_11_server:tcp_server_example",]
}

创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\tcp_11_server文件夹

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\tcp_11_server\BUILD.gn文件

#Copyright (C) 2021 HiHope Open Source Organization .
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#
#limitations under the License.static_library("tcp_server_example") {# uncomment one of following line, to enable one test:sources = ["tcp_server_example.c"]sources += ["wifi_connecter.c"]include_dirs = ["//utils/native/lite/include","//kernel/liteos_m/kal","//foundation/communication/wifi_lite/interfaces/wifiservice",]
}

添加了wifi_connecter.c文件的编译,这个文件中有链接wifi的函数。

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\tcp_11_server\net_common.h文件,文件主要引入一些头文件。

/** Copyright (C) 2021 HiHope Open Source Organization .* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and** limitations under the License.*/#ifndef NET_COMMON_H
#define NET_COMMON_H// __arm__ and __aarch64__ for HarmonyOS with liteos-a kernel
// __i386__ and __x86_64__ for Unix like OS
#if defined(__arm__) || defined(__aarch64__) || defined(__i386__) || defined(__x86_64__)
#define HAVE_BSD_SOCKET 1
#else
#define HAVE_BSD_SOCKET 0
#endif#if defined(__riscv) // for wifiiot(HarmonyOS on Hi3861 with liteos-m kernel)
#define HAVE_LWIP_SOCKET 1
#else
#define HAVE_LWIP_SOCKET 0
#endif#if HAVE_BSD_SOCKET
#include <sys/types.h>  // for AF_INET SOCK_STREAM
#include <sys/socket.h> // for socket
#include <netinet/in.h> // for sockaddr_in
#include <arpa/inet.h> // for inet_pton
#elif HAVE_LWIP_SOCKET
#include "lwip/sockets.h"
#ifndef close
#define close(fd) lwip_close(fd)
#endif
#else
#error "Unknow platform!"
#endif#endif  // NET_COMMON_H

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\tcp_11_server\wifi_connecter.h文件,该头文件包含wifi连接的宏。

/** Copyright (C) 2021 HiHope Open Source Organization .* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and** limitations under the License.*/#ifndef WIFI_CONNECTER_H
#define WIFI_CONNECTER_H#include "wifi_device.h"#ifndef PARAM_HOTSPOT_SSID
#define PARAM_HOTSPOT_SSID "HarmonyOS"   // your AP SSID
#endif#ifndef PARAM_HOTSPOT_PSK
#define PARAM_HOTSPOT_PSK  "1234567890"  // your AP PSK
#endif#ifndef PARAM_HOTSPOT_TYPE
#define PARAM_HOTSPOT_TYPE WIFI_SEC_TYPE_PSK // defined in wifi_device_config.h
#endif#ifndef PARAM_SERVER_ADDR
#define PARAM_SERVER_ADDR "192.168.1.100" // your PC IP address
#endif#ifndef PARAM_SERVER_PORT
#define PARAM_SERVER_PORT 5678
#endifint ConnectToHotspot(WifiDeviceConfig* apConfig);void DisconnectWithHotspot(int netId);#endif  // WIFI_CONNECTER_H

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\tcp_11_server\wifi_connecter.c文件,wifi连接的实现。

/** Copyright (C) 2021 HiHope Open Source Organization .* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and** limitations under the License.*/#include "wifi_device.h"
#include "cmsis_os2.h"#include "lwip/netifapi.h"
#include "lwip/api_shell.h"#define IDX_0          0
#define IDX_1          1
#define IDX_2          2
#define IDX_3          3
#define IDX_4          4
#define IDX_5          5
#define DELAY_TICKS_10     (10)
#define DELAY_TICKS_100    (100)static void PrintLinkedInfo(WifiLinkedInfo* info)
{if (!info) return;static char macAddress[32] = {0};unsigned char* mac = info->bssid;snprintf(macAddress, sizeof(macAddress), "%02X:%02X:%02X:%02X:%02X:%02X",mac[IDX_0], mac[IDX_1], mac[IDX_2], mac[IDX_3], mac[IDX_4], mac[IDX_5]);printf("bssid: %s, rssi: %d, connState: %d, reason: %d, ssid: %s\r\n",macAddress, info->rssi, info->connState, info->disconnectedReason, info->ssid);
}static volatile int g_connected = 0;static void OnWifiConnectionChanged(int state, WifiLinkedInfo* info)
{if (!info) return;printf("%s %d, state = %d, info = \r\n", __FUNCTION__, __LINE__, state);PrintLinkedInfo(info);if (state == WIFI_STATE_AVALIABLE) {g_connected = 1;} else {g_connected = 0;}
}static void OnWifiScanStateChanged(int state, int size)
{printf("%s %d, state = %X, size = %d\r\n", __FUNCTION__, __LINE__, state, size);
}static WifiEvent g_defaultWifiEventListener = {.OnWifiConnectionChanged = OnWifiConnectionChanged,.OnWifiScanStateChanged = OnWifiScanStateChanged
};static struct netif* g_iface = NULL;err_t netifapi_set_hostname(struct netif *netif, char *hostname, u8_t namelen);int ConnectToHotspot(WifiDeviceConfig* apConfig)
{WifiErrorCode errCode;int netId = -1;errCode = RegisterWifiEvent(&g_defaultWifiEventListener);printf("RegisterWifiEvent: %d\r\n", errCode);errCode = EnableWifi();printf("EnableWifi: %d\r\n", errCode);errCode = AddDeviceConfig(apConfig, &netId);printf("AddDeviceConfig: %d\r\n", errCode);g_connected = 0;errCode = ConnectTo(netId);printf("ConnectTo(%d): %d\r\n", netId, errCode);while (!g_connected) { // wait until connect to APosDelay(DELAY_TICKS_10);}printf("g_connected: %d\r\n", g_connected);g_iface = netifapi_netif_find("wlan0");if (g_iface) {err_t ret = 0;char* hostname = "rtplay";ret = netifapi_set_hostname(g_iface, hostname, strlen(hostname));printf("netifapi_set_hostname: %d\r\n", ret);ret = netifapi_dhcp_start(g_iface);printf("netifapi_dhcp_start: %d\r\n", ret);osDelay(DELAY_TICKS_100); // wait DHCP server give me IP
#if 1ret = netifapi_netif_common(g_iface, dhcp_clients_info_show, NULL);printf("netifapi_netif_common: %d\r\n", ret);
#else// 下面这种方式也可以打印 IP、网关、子网掩码信息ip4_addr_t ip = {0};ip4_addr_t netmask = {0};ip4_addr_t gw = {0};ret = netifapi_netif_get_addr(g_iface, &ip, &netmask, &gw);if (ret == ERR_OK) {printf("ip = %s\r\n", ip4addr_ntoa(&ip));printf("netmask = %s\r\n", ip4addr_ntoa(&netmask));printf("gw = %s\r\n", ip4addr_ntoa(&gw));}printf("netifapi_netif_get_addr: %d\r\n", ret);
#endif}return netId;
}void DisconnectWithHotspot(int netId)
{if (g_iface) {err_t ret = netifapi_dhcp_stop(g_iface);printf("netifapi_dhcp_stop: %d\r\n", ret);}WifiErrorCode errCode = Disconnect(); // disconnect with your APprintf("Disconnect: %d\r\n", errCode);errCode = UnRegisterWifiEvent(&g_defaultWifiEventListener);printf("UnRegisterWifiEvent: %d\r\n", errCode);RemoveDevice(netId); // remove AP configprintf("RemoveDevice: %d\r\n", errCode);errCode = DisableWifi();printf("DisableWifi: %d\r\n", errCode);
}

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\tcp_11_server\tcp_server_example.c文件

/** Copyright (C) 2021 HiHope Open Source Organization .* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and** limitations under the License.*/#include <errno.h>
#include <stdio.h>
#include <string.h>
// #include <stddef.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"#include "net_common.h"
#include "wifi_connecter.h"#define DELAY_1S  (1)
#define STACK_SIZE         (10240)
#define DELAY_TICKS_10     (10)
#define DELAY_TICKS_100    (100)static char request[128] = "";
void TcpServerTest(void)
{WifiDeviceConfig config = {0};// 准备AP的配置参数// strcpy(config.ssid, PARAM_HOTSPOT_SSID);// strcpy(config.preSharedKey, PARAM_HOTSPOT_PSK);strcpy_s(config.ssid, WIFI_MAX_SSID_LEN, PARAM_HOTSPOT_SSID);strcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, PARAM_HOTSPOT_PSK);config.securityType = PARAM_HOTSPOT_TYPE;osDelay(DELAY_TICKS_10);int netId = ConnectToHotspot(&config);ssize_t retval = 0;int backlog = 1;int sockfd = socket(AF_INET, SOCK_STREAM, 0); // TCP socketint connfd = -1;struct sockaddr_in clientAddr = {0};socklen_t clientAddrLen = sizeof(clientAddr);struct sockaddr_in serverAddr = {0};serverAddr.sin_family = AF_INET;serverAddr.sin_port = htons(PARAM_SERVER_PORT);  // 端口号,从主机字节序转为网络字节序serverAddr.sin_addr.s_addr = htonl(INADDR_ANY); // 允许任意主机接入, 0.0.0.0retval = bind(sockfd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); // 绑定端口if (retval < 0) {printf("bind failed, %ld!\r\n", retval);goto do_cleanup;}printf("bind to port %hu success!\r\n", PARAM_SERVER_PORT);retval = listen(sockfd, backlog); // 开始监听if (retval < 0) {printf("listen failed!\r\n");goto do_cleanup;}printf("listen with %d backlog success!\r\n", backlog);// 接受客户端连接,成功会返回一个表示连接的 socket , clientAddr 参数将会携带客户端主机和端口信息 ;失败返回 -1// 此后的 收、发 都在 表示连接的 socket 上进行;之后 sockfd 依然可以继续接受其他客户端的连接,//  UNIX系统上经典的并发模型是“每个连接一个进程”——创建子进程处理连接,父进程继续接受其他客户端的连接//  鸿蒙liteos-a内核之上,可以使用UNIX的“每个连接一个进程”的并发模型//     liteos-m内核之上,可以使用“每个连接一个线程”的并发模型connfd = accept(sockfd, (struct sockaddr *)&clientAddr, &clientAddrLen);if (connfd < 0) {printf("accept failed, %d, %d\r\n", connfd, errno);goto do_cleanup;}printf("accept success, connfd = %d!\r\n", connfd);printf("client addr info: host = %s, port = %hu\r\n", inet_ntoa(clientAddr.sin_addr), ntohs(clientAddr.sin_port));// 后续 收、发 都在 表示连接的 socket 上进行;retval = recv(connfd, request, sizeof(request), 0);if (retval < 0) {printf("recv request failed, %ld!\r\n", retval);goto do_disconnect;}printf("recv request{%s} from client done!\r\n", request);retval = send(connfd, request, strlen(request), 0);if (retval <= 0) {printf("send response failed, %ld!\r\n", retval);goto do_disconnect;}printf("send response{%s} to client done!\r\n", request);do_disconnect:sleep(DELAY_1S);close(connfd);sleep(DELAY_1S); // for debugdo_cleanup:printf("do_cleanup...\r\n");close(sockfd);DisconnectWithHotspot(netId);
}SYS_RUN(TcpServerTest);

使用build,编译成功后,使用upload进行烧录。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/367300.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【机器学习】在【Pycharm】中的实践教程:使用【逻辑回归模型】进行【乳腺癌检测】

目录 案例背景 具体问题 1. 环境准备 小李的理解 知识点 2. 数据准备 2.1 导入必要的库和数据集 小李的理解 知识点 2.2 数据集基本信息 小李的理解 知识点 注意事项 3. 数据预处理 3.1 划分训练集和测试集 小李的理解 知识点 注意事项 3.2 数据标准化 小李…

前端Web开发HTML5+CSS3+移动web视频教程 Day3 CSS 第1天

P29 - P43 从此开始进入 CSS 的学习。前面都是 HTML 的学习。 CSS 的作用&#xff1a;美化。 HTML 只是规定了网页内容有哪些&#xff0c;在网页中显示的位置默认是从上到下显示&#xff0c;还带有默认效果&#xff0c;比如超链接有颜色有下划线&#xff0c;无序列表有小圆点…

MeEdu网校系统搜索功能问题处理

MeEdu通过 MeiliSearch 实现全文搜索服务。 一、下载 MeiliSearch 程序 https://github.com/meilisearch/MeiliSearch/releases/tag/v0.24.0 只能下载 v0.24.0 版本&#xff0c;其版本不支持 下载 meilisearch-linux-amd64就可以了 二、上传 MeiliSearch 三、启动命令如下…

华为云安全防护,九河云综合分解优劣势分析

随着全球化的发展&#xff0c;越来越多的企业开始寻求在国际市场上扩展业务&#xff0c;这一趋势被称为企业出海。然而&#xff0c;企业在海外扩张面临诸多隐患与安全挑战&#xff0c;其中因为地域的不同&#xff0c;在安全性方面与国内相比会变得薄弱&#xff0c;从而导致被黑…

antd+vue——实现table组件跨页多选,已选择数据禁止第二次重复选择

需求场景&#xff1a;点击【新增】按钮可以在分页弹窗中跨页多选选择数据后添加到页面中&#xff0c;再次点击【新增】&#xff0c;已经选择过的数据则置灰不让重复选择。 选择后&#xff0c;置灰 点击【确定】数据添加到页面中&#xff0c;可再次点击【新增】进行添加数据 …

FastGPT 手动部署错误:MongooseServerSelectionError: getaddrinfo EAI_AGAIN mongo

在运行 FastGPT 时&#xff0c;mongodb 报如下错误&#xff1a; MongooseServerSelectionError: getaddrinfo EAI_AGAIN mongo 这是因为 mongo 没有解析出来&#xff0c;在 hosts 文件中添加如下信息&#xff1a; 127.0.0.1 mongo 重新运行 FastGPT 即可。 参考链接&#xff…

基于web的产品管理系统

文章目录 项目介绍主要功能截图:部分代码展示设计总结项目获取方式🍅 作者主页:超级无敌暴龙战士塔塔开 🍅 简介:Java领域优质创作者🏆、 简历模板、学习资料、面试题库【关注我,都给你】 🍅文末获取源码联系🍅 项目介绍 基于web的产品管理系统,java项目。 ecli…

被⽹络罪犯利⽤的5⼤ChatGPT越狱提⽰

⾃ChatGPT发布的近18个月以来&#xff0c;⽹络罪犯们已经能够利⽤⽣成式AI进⾏攻击。OpenAI在其内容政策中制定了限制措施&#xff0c;以阻⽌⽣成恶意内容。作为回应&#xff0c;攻击者们创建了⾃⼰的⽣成式AI平台&#xff0c;如 WormGPT和FraudGPT&#xff0c;并且他们还分享了…

Jmeter下载、安装及配置

1 Jmeter介绍 Jmeter是进行负载测试的工具&#xff0c;可以在任何支持Java虚拟机环境的平台上运行&#xff0c;比如Windows、Linux、Mac。 Jmeter模拟一组用户向目标服务器发送请求&#xff0c;并统计目标服务器的性能信息&#xff0c;比如CPU、memory usage。 2 Jmeter下载 …

应用密码学—(扩展)欧几里得、DES、RSA、SHA-1算法

1. 欧几里得算法 1.1 分析算法的实现原理 欧几里德&#xff08;Euclid&#xff09;算法&#xff0c;也既常说的“辗转相除法”&#xff0c;公式为gcd(m, n) { return gcd(n, m%n); }&#xff0c;对于任意两个正整数m、n&#xff0c;每次求的一个数字r m % n&#xff0c;然后把…

C语言快速学习笔记

学习网站&#xff1a;C 语言教程 | 菜鸟教程 (runoob.com)C 语言教程 | 菜鸟教程 (runoob.com)C 语言教程 | 菜鸟教程 (runoob.com) 这个网站知识完整&#xff0c;讲解清晰。 在线C语言编程工具&#xff1a;菜鸟教程在线编辑器 (runoob.com) 国外学习网站&#xff1a;C语言介…

难道 Java 已经过时了?

当一门技术已经存在许多年了&#xff0c;它可能会失去竞争力&#xff0c;而后黯然退场&#xff0c;默默地离开&#xff0c;这对大部分的人来说就已经算是过时了。 Java 于 1995 年正式上线&#xff0c;至今已经走过了 27 个年头&#xff0c;在众多编程技术里算是年龄比较大的语…

【C++】开源:量化金融计算库QuantLib配置与使用

&#x1f60f;★,:.☆(&#xffe3;▽&#xffe3;)/$:.★ &#x1f60f; 这篇文章主要介绍量化交易库QuantLib配置与使用。 无专精则不能成&#xff0c;无涉猎则不能通。——梁启超 欢迎来到我的博客&#xff0c;一起学习&#xff0c;共同进步。 喜欢的朋友可以关注一下&#…

【高中数学/基本不等式】已知:a,b皆为正实数,且3a+2b=10 求:3a开方+2b开方的最大值?

【题目】 已知&#xff1a;a,b皆为正实数&#xff0c;且3a2b10 求&#xff1a;3a开方2b开方的最大值&#xff1f; 【解答】 解法一&#xff1a;&#xff08;基本不等式&#xff09; 原式^23a2*根号下(3a*2b)2b102*根号下(3a*2b)<103a2b101020 答&#xff1a;3a开方2b…

[漏洞复现] MetInfo5.0.4文件包含漏洞

[漏洞复现] MetInfo5.0.4文件包含漏洞 MetInfo5.0.4 漏洞代码审计 漏洞出现在about/index.php中&#xff0c;因为利用了动态地址&#xff0c;所以存在漏洞。 漏洞检查语句&#xff08;&#xff01;192.168.109.100是我的服务器ip&#xff0c;需要换成自己的&#xff09;&…

双曲方程初值问题的差分逼近(迎风格式)

稳定性: 数值例子 例一 例二 代码 % function chap4_hyperbolic_1st0rder_1D % test the upwind scheme for 1D hyperbolic equation % u_t + a*u_x = 0,0<x<L,O<t<T, % u(x,0) = |x-1|,0<X<L, % u(0,t) = 1% foundate = 2015-4-22’; % chgedate = 202…

SpringBoot 如何处理跨域请求?你说的出几种方法?

引言&#xff1a;在现代的Web开发中&#xff0c;跨域请求&#xff08;Cross-Origin Resource Sharing&#xff0c;CORS&#xff09;是一个常见的挑战。随着前后端分离架构的流行&#xff0c;前端应用通常运行在一个与后端 API 不同的域名或端口上&#xff0c;这就导致了浏览器的…

方法的用法

一.简介 目前为止我给出的所有的案例都是将代码放在main方法中&#xff0c;就会产生一些问题&#xff1a; 代码冗长&#xff0c;不利于维护变量过多&#xff0c;想不出那么多的变量名没有重用性 那么该如何解决呢&#xff1f; 我们可以编写功能性的代码块&#xff0c;来被ma…

华为DCN之:SDN和NFV

1. SDN概述 1.1 SDN的起源 SDN&#xff08;Software Defined Network&#xff09;即软件定义网络。是由斯坦福大学Clean Slate研究组提出的一种新型网络创新架构。其核心理念通过将网络设备控制平面与数据平面分离&#xff0c;从而实现了网络控制平面的集中控制&#xff0c;为…

【STM32 RTC实时时钟如何配置!超详细的解析和超简单的配置,附上寄存器操作】

STM32 里面RTC模块和时钟配置系统(RCC_BDCR寄存器)处于后备区域&#xff0c;即在系统复位或从待机模式唤醒后&#xff0c;RTC的设置和时间维持不变。因为系统对后备寄存器和RTC相关寄存器有写保护&#xff0c;所以如果想要对后备寄存器和RTC进行访问&#xff0c;则需要通过操作…