当前位置: 首页 > article >正文

WebSocket的原理及QT示例

一.WebSocket 介绍

1.概述

WebSocket 是一种在单个 TCP 连接上进行全双工通讯的协议,它在 2011 年被 IETF 定为标准 RFC 6455,并由 RFC7936 补充规范。与传统的 HTTP 协议不同,WebSocket 允许服务器和客户端之间进行实时、双向的数据传输,打破了 HTTP 协议请求 - 响应的模式限制,大大提高了数据传输的效率和实时性。

2.特点

全双工通信:服务器和客户端可以在任意时刻向对方发送数据,无需等待对方的请求。

实时性强:由于采用了全双工通信,数据可以即时传输,非常适合实时性要求较高的应用场景,如在线聊天、实时数据监控等。

较少的开销:WebSocket 握手阶段使用 HTTP 协议,建立连接后,数据传输不再需要像 HTTP 那样携带大量的头部信息,减少了数据传输的开销。

跨域支持:WebSocket 支持跨域通信,方便不同域名之间的服务器和客户端进行数据交互。

客户端与服务器交互图

3.应用场景

实时聊天应用:如在线客服、社交聊天等,用户可以即时收到对方发送的消息。

实时数据监控:如股票行情、传感器数据监控等,服务器可以实时将最新的数据推送给客户端。

多人在线游戏:实现游戏中玩家之间的实时交互,如位置更新、动作同步等。

二.代码示例

1.客户端代码

#include "Clientdialog.h"

#include <QLabel>

#include <QWidget>

#include <QHBoxLayout>

#include <QVBoxLayout>

#include <QtCore>

#include <QDebug>

#include <iostream>

ClientDialog::ClientDialog(QWidget *parent)

    : QWidget(parent)

{

    //layout1

    QLabel *iplabel = new QLabel("Server IP");

    m_iplineedit =new QLineEdit;

    m_iplineedit->setText("127.0.0.1");

    QLabel *portlabel =new QLabel("Server端口");

    m_portspinbox = new QSpinBox;

    m_portspinbox->setRange(0,65535);

    m_portspinbox->setValue(5123);

    m_linkbutton = new QPushButton("连接");

    m_disconnectbutton = new QPushButton("断开");

    pButtonGroup = new QButtonGroup();

    pButtonGroup->setExclusive(true);

    m_linkbutton->setCheckable(true);

    m_disconnectbutton->setCheckable(true);

    pButtonGroup->addButton(m_linkbutton,0);

    pButtonGroup->addButton(m_disconnectbutton,1);

    QHBoxLayout *qhboxlayout1 = new QHBoxLayout;

    qhboxlayout1->addWidget(iplabel);

    qhboxlayout1->addWidget(m_iplineedit);

    qhboxlayout1->addWidget(portlabel);

    qhboxlayout1->addWidget(m_portspinbox);

    qhboxlayout1->addWidget(m_linkbutton);

    qhboxlayout1->addWidget(m_disconnectbutton);

    //layout2

    QLabel *sendmessagelabel = new QLabel("发送消息");

    QHBoxLayout *qhboxlayout2 = new QHBoxLayout;

    qhboxlayout2->addWidget(sendmessagelabel);

    //layout3

    m_sendmessagetextedit = new QTextEdit;

    m_sendmessagetextedit->setFixedHeight(50);

    m_sendbutton = new QPushButton("发送");

    m_sendbutton->setFixedHeight(50);

    QHBoxLayout *qhboxlayout3 = new QHBoxLayout;

    qhboxlayout3->addWidget(m_sendmessagetextedit);

    qhboxlayout3->addWidget(m_sendbutton);

    //layout4

    QLabel *receivemessagelabel = new QLabel("接收消息");

    QHBoxLayout *qhboxlayout4 = new QHBoxLayout;

    qhboxlayout4->addWidget(receivemessagelabel);

    //layout5

    m_receivemessageTextEdit = new QTextEdit;

    QHBoxLayout *qhboxlayout5 = new QHBoxLayout;

    qhboxlayout5->addWidget(m_receivemessageTextEdit);

    m_receivemessageTextEdit->setReadOnly(true);

    //layout6

    statusLabel = new QLabel("连接状态");

    m_clean = new QPushButton("清除");

    QHBoxLayout *qhboxlayout6 = new QHBoxLayout;

    qhboxlayout6->addWidget(statusLabel);

    qhboxlayout6->addStretch();

    qhboxlayout6->addWidget(m_clean);

    //

    QVBoxLayout *mainlayout = new QVBoxLayout;

    mainlayout->addLayout(qhboxlayout1,1);

    mainlayout->addLayout(qhboxlayout2,0.5);

    mainlayout->addLayout(qhboxlayout3,1);

    mainlayout->addLayout(qhboxlayout4,0.5);

    mainlayout->addLayout(qhboxlayout5,3);

    mainlayout->addLayout(qhboxlayout6,1);

    setLayout(mainlayout);

    setWindowTitle("Websocket Client");

    this->setFixedSize(800, 600); // 窗口固定为800x600像素,无法缩放

    connect(m_linkbutton,SIGNAL(clicked(bool)),this,SLOT(connectToServer()));

    connect(m_disconnectbutton,SIGNAL(clicked(bool)),this,SLOT(stopClicked()));

    connect(m_sendbutton,SIGNAL(clicked(bool)),this,SLOT(onSendButtonClicked()));

    connect(m_clean,SIGNAL(clicked(bool)),this,SLOT(onCleanButtonClicked()));

    connect(&m_websocket,SIGNAL(connected()),this,SLOT(onconnected()));

    connect(&m_websocket,SIGNAL(disconnected()),this,SLOT(closeConnection()));

    connect(&m_websocket,SIGNAL(textMessageReceived(QString)),this,SLOT(onTextMessageReceived(QString)));

}

ClientDialog::~ClientDialog()

{

    m_websocket.errorString();

    m_websocket.close();

}

//断开连接操作

void ClientDialog::closeConnection(){

    m_linkbutton->setEnabled(true);

    m_disconnectbutton->setEnabled(false);

    m_sendmessagetextedit->setEnabled(false);

    m_sendbutton->setEnabled(false);

    m_receivemessageTextEdit->setEnabled(false);

    m_clean->setEnabled(false);

    statusLabel->setText(tr("disconnected"));

}

//连接服务器

void ClientDialog::connectToServer()

{

    QString path = QString("ws://%1:%2").arg(m_iplineedit->text()).arg(m_portspinbox->text());

    QUrl url = QUrl(path);

    m_websocket.open(url);

}

//连接上之后

void ClientDialog::onconnected(){

    qDebug() << "hello word!";

    statusLabel->setText(tr("connected"));

    m_linkbutton->setEnabled(false);

    m_disconnectbutton->setEnabled(true);

    m_sendmessagetextedit->setEnabled(true);

    m_sendbutton->setEnabled(true);

    m_receivemessageTextEdit->setEnabled(true);

    m_clean->setEnabled(true);

}

//收到消息

void ClientDialog::onTextMessageReceived(const QString &message)

{

    QString time = current_date_time->currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz ddd");

    m_receivemessageTextEdit->setText(time + "\r\n" + "message: " + message);

}

//断开

void ClientDialog::stopClicked()

{

    m_websocket.close();

}

//发送消息

void ClientDialog::onSendButtonClicked()

{

    QString msg= m_sendmessagetextedit->document()->toPlainText();

    m_websocket.sendTextMessage(msg);

}

//清除内容

void ClientDialog::onCleanButtonClicked()

{

    m_receivemessageTextEdit->clear();

}

2.服务端代码

#include "webserver.h"

#include "ui_webserver.h"

#include <QtCore/QVariant>

#include <QtWidgets/QApplication>

#include <QtWidgets/QButtonGroup>

#include <QtWidgets/QHeaderView>

#include <QtWidgets/QLabel>

#include <QtWidgets/QListWidget>

#include <QtWidgets/QPushButton>

#include <QtWidgets/QSpinBox>

#include <QtWidgets/QTextBrowser>

#include <QtWidgets/QWidget>

#include <QHBoxLayout>

webserver::webserver(QWidget *parent) :

    QWidget(parent),

    ui(new Ui::webserver)

{

    ui->setupUi(this);

    {

         //qhboxLayout1部分代码

         QLabel* monitorLabel= new QLabel("监听端口");

         m_monitorSpinBox = new QSpinBox();

         m_monitorSpinBox->setRange(0,65535);

         m_monitorSpinBox->setValue(5123);

         m_startButton = new QPushButton("启动服务");

         m_stopButton = new QPushButton("停止服务");

         m_stopButton->setEnabled(false);

         QHBoxLayout *qhboxLayout = new QHBoxLayout;

         qhboxLayout->addWidget(monitorLabel);

         qhboxLayout->addWidget(m_monitorSpinBox);

         qhboxLayout->addWidget(m_startButton);

         qhboxLayout->addWidget(m_stopButton);

        //qhboxLayout2部分代码

          QLabel* sendLabel=new QLabel("发送消息");

          sendLabel->setFixedHeight(30);

          QHBoxLayout *qhboxLayout2 = new QHBoxLayout;

          qhboxLayout2->addWidget(sendLabel);

        //qhboxLayout3部分代码

          m_sendTextedit = new QTextEdit;

          m_sendTextedit = new QTextEdit();

          m_sendTextedit->setEnabled(false);

          m_sendTextedit->setFixedHeight(80);

          m_sendButton= new QPushButton("发送");

          m_sendButton->setEnabled(false);

          m_sendButton->setFixedHeight(50);

          QHBoxLayout *qhboxlayout3 = new QHBoxLayout;

          qhboxlayout3->addWidget(m_sendTextedit,2);

          qhboxlayout3->addWidget(m_sendButton,1);

        //qvboxlayout411

          QLabel* receiveLabel = new QLabel("接收消息");

          receiveLabel->setFixedHeight(30);

          m_receiveTextEdit = new QTextEdit();

          m_receiveTextEdit->setReadOnly(true);

          QVBoxLayout *qvboxlayout411 = new QVBoxLayout;

          qvboxlayout411->addWidget(receiveLabel);

          qvboxlayout411->addWidget(m_receiveTextEdit);

            //qhboxlayout412

          m_cleanButton = new QPushButton("清除");

          m_cleanButton->setEnabled(false);

          QHBoxLayout *qhboxlayout412 = new QHBoxLayout;

          qhboxlayout412->addStretch();

          qhboxlayout412->addWidget(m_cleanButton);

        //qvboxlayout41

          QVBoxLayout *qvboxlayout41 = new QVBoxLayout;

          qvboxlayout41->addLayout(qvboxlayout411);

          qvboxlayout41->addLayout(qhboxlayout412);

        //qvboxlayout42

          QLabel* linkclientLabel=new QLabel("连接客户端");

          linkclientLabel->setFixedHeight(30);

          m_linkclientListWidget=new QListWidget;

          QVBoxLayout* qvboxlayout42 = new QVBoxLayout;

          qvboxlayout42->addWidget(linkclientLabel);

          qvboxlayout42->addWidget(m_linkclientListWidget);

        //qvboxlayout4

          QHBoxLayout *qhboxlayout4 = new QHBoxLayout;

          qhboxlayout4->addLayout(qvboxlayout41,2);

          qhboxlayout4->addLayout(qvboxlayout42,1);

         //mainlayout

          QVBoxLayout *mainLayout = new QVBoxLayout;

          mainLayout->addLayout(qhboxLayout,1);

          mainLayout->addLayout(qhboxLayout2,1);

          mainLayout->addLayout(qhboxlayout3,1);

          mainLayout->addLayout(qhboxlayout4,3);

          this->setLayout(mainLayout);

          this->setWindowTitle("Websocket Server -- Neo");

          this->setFixedSize(800, 600); // 窗口固定为800x600像素,无法缩放

    }

    m_WebSocketServer=new QWebSocketServer("server",QWebSocketServer::NonSecureMode);

    connect(m_WebSocketServer,SIGNAL(newConnection()),this,SLOT(onNewConnection()));

    connect(m_WebSocketServer, SIGNAL(closed()), this, SLOT(onClosed()));

    connect(m_WebSocketServer, SIGNAL(serverError(QWebSocketProtocol::CloseCode)),

            this, SLOT(onServerError(QWebSocketProtocol::CloseCode)));

    connect(m_startButton,SIGNAL(clicked(bool)),this,SLOT(onStartButtonClick()));

    connect(m_stopButton,SIGNAL(clicked(bool)),this,SLOT(onStopButtonClick()));

    connect(m_cleanButton,SIGNAL(clicked(bool)),this,SLOT(onCleanButtonClick()));

    connect(m_sendButton,SIGNAL(clicked(bool)),this,SLOT(onSendButtonClick()));

}

webserver::~webserver()

{

    if(m_WebSocketServer)

    {

        m_WebSocketServer->close();

    }

    delete ui;

}

//开启服务

void webserver::onStartButtonClick(){

    int i_port = m_monitorSpinBox->text().toInt();

    m_WebSocketServer->listen(QHostAddress::Any,i_port);

    m_startButton->setEnabled(false);

    m_stopButton->setEnabled(true);

    qDebug()<<m_WebSocketServer->isListening();

    qDebug()<<m_WebSocketServer->serverPort();

    qDebug()<<m_WebSocketServer->serverAddress();

}

//停止服务

void webserver::onStopButtonClick(){

    m_startButton->setEnabled(true);

    m_stopButton->setEnabled(false);

    m_WebSocketServer->close();

}

//发送信息

void webserver::onSendButtonClick(){

    QString msg = m_sendTextedit->document()->toPlainText();

    int currenRow = m_linkclientListWidget->currentRow();//当前单击选中ListWidget控件的行号

    if(currenRow==-1)

    {

        currenRow = 0;

    }

    QString key = m_linkclientListWidget->item(currenRow)->text();

    if(_hashIpPort2PWebSocket.contains(key))

    {

        _hashIpPort2PWebSocket.value(key)->sendTextMessage(msg);

    }

}

void webserver::onCleanButtonClick(){

    m_receiveTextEdit->clear();

}

//连接上之后

void webserver::onNewConnection(){

    qDebug() << "connect ok";

    m_startButton->setEnabled(false);

    m_stopButton->setEnabled(true);

    m_sendTextedit->setEnabled(true);

    m_sendButton->setEnabled(true);

    m_cleanButton->setEnabled(true);

    QWebSocket *pWebSocket = m_WebSocketServer->nextPendingConnection();

    connect(pWebSocket,SIGNAL(textMessageReceived(QString)),this,SLOT(slot_processTextMessage(QString)));

    connect(pWebSocket,SIGNAL(disconnected()),this,SLOT(slot_socketDisconnected()));

    connect(pWebSocket, SIGNAL(error(QAbstractSocket::SocketError)),

            this      , SLOT(slot_error(QAbstractSocket::SocketError)));

    quint32 ipv4Address =  pWebSocket->peerAddress().toIPv4Address();

    QString ipString = QHostAddress(ipv4Address).toString();

    _hashIpPort2PWebSocket.insert(QString("%1-%2").arg(ipString).arg(pWebSocket->peerPort()),pWebSocket);

    QString item = QString("%1-%2").arg(ipString).arg(pWebSocket->peerPort());

    m_linkclientListWidget->addItem(item);

}

//停止之后

void webserver::onClosed()

{

    QList<QWebSocket *> _listWebSocket = _hashIpPort2PWebSocket.values();

    for(int index = 0; index < _listWebSocket.size(); index++)

    {

        _listWebSocket.at(index)->close();

    }

    _hashIpPort2PWebSocket.clear();

    m_linkclientListWidget->clear();

}

//连接错误

void webserver::onServerError(QWebSocketProtocol::CloseCode closeCode)

{

    QWebSocket *pWebSocket = dynamic_cast<QWebSocket *>(sender());

    if(!pWebSocket)

    {

        return;

    }

}

void webserver::slot_error(QAbstractSocket::SocketError error)

{

    QWebSocket *pWebSocket = dynamic_cast<QWebSocket *>(sender());

    if(!pWebSocket)

    {

        return;

    }

}

//收到消息并显示

void webserver::slot_processTextMessage(QString message){

    QWebSocket *pWebSocket = dynamic_cast<QWebSocket *>(sender());

    if(!pWebSocket)

    {

        return;

    }

    QString time = current_date_time->currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz ddd");

    quint32 ipv4Address =  pWebSocket->peerAddress().toIPv4Address();

    QString ipString = QHostAddress(ipv4Address).toString();

    QString item = QString("IP: %1, port: %2").arg(ipString).arg(pWebSocket->peerPort());

    m_receiveTextEdit->append(time+ "\r\n" + item + "\r\n" + "message: " + message + "\r\n");

    //qDebug()<< pWebSocket->peerAddress().toString();

    //qDebug() << "Client IP address: " << ipString;

}

//连接断开的操作

void webserver::slot_socketDisconnected(){

    QWebSocket *pWebSocket = dynamic_cast<QWebSocket *>(sender());

    if(!pWebSocket)

    {

        return;

    }

    //qDebug() << __FILE__ << __LINE__ << __FUNCTION__;

    quint32 ipv4Address =  pWebSocket->peerAddress().toIPv4Address();

    QString ipString = QHostAddress(ipv4Address).toString();

    QString item1 = QString("%1-%2").arg(ipString).arg(pWebSocket->peerPort());

    _hashIpPort2PWebSocket.remove(QString("%1-%2").arg(ipString).arg(pWebSocket->peerPort()));

    QListWidgetItem *item3;

    for(int i=0;i<m_linkclientListWidget->count();i++)

    {

        QString str = m_linkclientListWidget->item(i)->text();

        if(str == item1)

        {

            item3 = m_linkclientListWidget->takeItem(i);

            m_linkclientListWidget->removeItemWidget(item3);

            delete item3;

        }

    }

}

void webserver::on_m_linkclientListWidget_clicked(const QModelIndex &index)

{

int currenRow = m_linkclientListWidget->currentRow();

}

3.完整工程代码下载

https://download.csdn.net/download/xieliru/90787178

相关文章:

WebSocket的原理及QT示例

一.WebSocket 介绍 1.概述 WebSocket 是一种在单个 TCP 连接上进行全双工通讯的协议&#xff0c;它在 2011 年被 IETF 定为标准 RFC 6455&#xff0c;并由 RFC7936 补充规范。与传统的 HTTP 协议不同&#xff0c;WebSocket 允许服务器和客户端之间进行实时、双向的数据传输&a…...

数据库故障排查指南以及各类常用数据库基础用法

数据库故障排查指南大纲 数据库故障排查的基本概念 数据库故障的定义与分类常见数据库故障的表现形式故障排查的重要性与目标 数据库故障通常指数据库系统在运行过程中出现的异常情况&#xff0c;导致数据无法正常访问或操作。故障可以分为硬件故障、软件故障、网络故障、配…...

Spring Boot动态配置修改全攻略

精心整理了最新的面试资料和简历模板&#xff0c;有需要的可以自行获取 点击前往百度网盘获取 点击前往夸克网盘获取 无需重启应用&#xff0c;实时更新配置的终极指南 在微服务架构中&#xff0c;动态配置管理是提高系统灵活性的关键技术。本文将通过4种主流方案&#xff0c…...

vue3:十二、图形看板- echart图表-柱状图、饼图

一、效果 如图展示增加了饼图和柱状图,并且优化了浏览器窗口大小更改,图表随着改变 二、 饼图 1、新建组件文件 新增组件EchartsExaminePie.vue,用于存储审核饼图的图表 2、写入组件信息 (1)视图层 写入一个div,写入变量chart和图表宽高 <template><div ref…...

2025年best好用的3dsmax插件和脚本

copitor 可以从一个3dsmax场景里将物体直接复制到另一个场景中 Move to surface 这个插件可以将一些物体放到一个平面上 instancer 实体器&#xff0c;举例&#xff1a;场景中有若干独立的光源&#xff0c;不是实体对象&#xff0c;我们可以使用instancer将他变成实体。 paste …...

趣谈Ai各种模型算法及应用

机器学习与深度学习模型选型终极指南&#xff1a;告别选择困难症&#xff01; 大家好&#xff01;今天&#xff0c;我们来聊一个让很多初学者甚至有经验的开发者都头疼的问题&#xff1a;面对琳琅满目的机器学习和深度学习模型&#xff0c;到底该如何选择&#xff1f;就像走进…...

HAProxy + Keepalived + Nginx 高可用负载均衡系统

1. 项目背景 在现代Web应用中&#xff0c;高可用性和负载均衡是两个至关重要的需求。本项目旨在通过HAProxy实现流量分发&#xff0c;通过Keepalived实现高可用性&#xff0c;通过Nginx提供后端服务。该架构能够确保在单点故障的情况下&#xff0c;系统仍然能够正常运行&#…...

vue2升级vue3

vue2升级vue3 父子自定义事件插槽差异 父子自定义事件 父组件的传给子组件的自定义事件以短横形式命名&#xff0c;例如&#xff1a;my-click 子组件声明该自定义事件时为 myClick 事件可以正常触发 插槽差异 vue2&#xff1a; <el-table-column:label"$t(hcp_devrs…...

5.12 note

Leetcode 图 邻接矩阵的dfs遍历 class Solution { private: vector<vector<int>> paths; vector<int> path; void dfs(vector<vector<int>>& graph, int node) { // 到n - 1结点了保存 if (node graph.size() - 1)…...

跨时钟域(CDC,clock domain crossing)信号处理

参考视频&#xff1a; 数字IC&#xff0c;FPGA秋招【单bit信号的CDC跨时钟域处理手撕代码合集】_哔哩哔哩_bilibili 一、亚稳态 原因是&#xff1a;建立时间和保持时间没有保持住。然后在下图的红框里面&#xff0c;产生亚稳态。因为电路反馈机制&#xff0c;最后大概率会恢复…...

鸿蒙HarmonyOS list优化一: list 结合 lazyforeach用法

list列表是开发中不可获取的&#xff0c;非常常用的组件&#xff0c;使用过程中会需要不断的优化&#xff0c;接下来我会用几篇文章进行list在纯原生的纯血鸿蒙的不断优化。我想进大厂&#xff0c;希望某位大厂的看到后能给次机会。 首先了解一下lazyforeach&#xff1a; Laz…...

OBS studio 减少音频中的杂音(噪音)

1. 在混音器中关闭除 麦克风 之外的所有的音频输入设备 2.在滤镜中增加“噪声抑制”和“噪声门限”...

基于神经网络的 YOLOv8、MobileNet、HigherHRNet 姿态检测比较研究

摘要 随着人工智能技术的飞速发展&#xff0c;基于神经网络的姿态检测技术在计算机视觉领域取得了显著进展。本文旨在深入比较分析当前主流的姿态检测模型&#xff0c;即 YOLOv8、MobileNet 和 HigherHRNet&#xff0c;从模型架构、性能表现、应用场景等多维度展开研究。通过详…...

智能手表 MCU 任务调度图

智能手表 MCU 任务调度图 处理器平台&#xff1a;ARM Cortex-M33 系统架构&#xff1a;事件驱动 多任务 RTOS RTOS&#xff1a;FreeRTOS&#xff08;或同类实时内核&#xff09; 一、任务调度概览 任务名称优先级周期性功能描述App_MainTask中否主循环调度器&#xff0c;系统…...

青少年编程与数学 02-019 Rust 编程基础 03课题、变量与可变性

青少年编程与数学 02-019 Rust 编程基础 03课题、变量与可变性 一、使用多个文件&#xff08;模块&#xff09;1. 创建包结构2. 在 main.rs 中引入模块示例&#xff1a;main.rs 3. 定义模块文件示例&#xff1a;module1.rs示例&#xff1a;module2.rs 4. 定义子模块示例&#x…...

S7-1500——零基础入门2、PLC的硬件架构

PLC的硬件架构 一,西门子PLC概述二,CPU介绍三,数字量模块介绍四,模拟量模块介绍五,其他模块介绍一,西门子PLC概述 本节主要内容 西门子PLC硬件架构,主要内容包括PLC概述、组成、功能及S7-1500 demo的组成与安装演示。 介绍了PLC的定义、功能、应用场合,以及与继电器控…...

前端面试宝典---webpack面试题

webpack 的 tree shaking 的原理 Webpack 的 Tree Shaking 过程主要包含以下步骤&#xff1a; 模块依赖分析&#xff1a;Webpack 首先构建一个完整的模块依赖图&#xff0c;确定每个模块之间的依赖关系。导出值分析&#xff1a;通过分析模块之间的 import 和 export&#xff…...

【PmHub后端篇】Skywalking:性能监控与分布式追踪的利器

在微服务架构日益普及的当下&#xff0c;对系统的性能监控和分布式追踪显得尤为重要。本文将详细介绍在 PmHub 项目中&#xff0c;如何使用 Skywalking 实现对系统的性能监控和分布式追踪&#xff0c;以及在这过程中的一些关键技术点和实践经验。 1 分布式链路追踪概述 在微服…...

Grafana v12.0 引入了多项新功能和改进

Grafana v12.0 引入了多项新功能和改进&#xff0c;旨在提升可观测性、仪表板管理和用户体验。以下是主要更新内容的总结&#xff1a; &#x1f680; 主要新功能与改进 1. Git 同步仪表板&#xff08;Git Sync&#xff09; Grafana v12.0 支持将仪表板直接同步到 GitHub 仓库…...

利用“Flower”实现联邦机器学习的实战指南

一个很尴尬的现状就是我们用于训练 AI 模型的数据快要用完了。所以我们在大量的使用合成数据&#xff01; 据估计&#xff0c;目前公开可用的高质量训练标记大约有 40 万亿到 90 万亿个&#xff0c;其中流行的 FineWeb 数据集包含 15 万亿个标记&#xff0c;仅限于英语。 作为…...

MongoDB使用x.509证书认证

文章目录 自定义证书生成CA证书生成服务器之间的证书生成集群证书生成用户证书 MongoDB配置java使用x.509证书连接MongoDBMongoShell使用证书连接 8.0版本的mongodb开启复制集&#xff0c;配置证书认证 自定义证书 生成CA证书 生成ca私钥&#xff1a; openssl genrsa -out ca…...

创始人 IP 的破局之道:从技术突围到生态重构的时代启示|创客匠人评述

在 2025 年的商业版图上&#xff0c;创始人 IP 正以前所未有的深度介入产业变革。当奥雅股份联合创始人李方悦在 “中国上市公司品牌价值榜” 发布会上&#xff0c;将 IP 赋能与城市更新大模型结合时&#xff0c;当马斯克在特斯拉财报电话会议上宣称 “未来属于自动驾驶和人形机…...

Gin 框架入门

Gin 框架入门 一、响应数据 JSON 响应 在 Web 开发中&#xff0c;JSON 是一种常用的数据交换格式。Gin 提供了简便的方法来响应 JSON 数据。 package mainimport ("github.com/gin-gonic/gin" )func main() {r : gin.Default()r.GET("/json", func(c *…...

【RabbitMQ】应用问题、仲裁队列(Raft算法)和HAProxy负载均衡

&#x1f525;个人主页&#xff1a; 中草药 &#x1f525;专栏&#xff1a;【中间件】企业级中间件剖析 一、幂等性保障 什么是幂等性&#xff1f; 幂等性是指对一个系统进行重复调用&#xff08;相同参数&#xff09;&#xff0c;无论同一操作执行多少次&#xff0c;这些请求…...

软件设计师-错题笔记-系统开发与运行

1. 解析&#xff1a; A&#xff1a;模块是结构图的基本成分之一&#xff0c;用矩形表示 B&#xff1a;调用表示模块之间的调用关系&#xff0c;通过箭头等符号在结构图中体现 C&#xff1a;数据用于表示模块之间的传递的信息&#xff0c;在结构图中会涉及数据的流向等表示 …...

硬件设备基础

一、ARM9 内核中有多少个通用寄存器&#xff1f;其中 sp、lr、pc、cpsr、spsr 的作用是什么&#xff1f; 在 ARM9 内核中&#xff0c;寄存器组织包含 37 个 通用寄存器&#xff0c;其中&#xff0c;有 13 个通用目的寄存器&#xff08;R0 - R12&#xff09;。 S3C2440 是 ARM 架…...

[编程基础] PHP · 学习手册

&#x1f525; 《PHP 工程师修炼之路&#xff1a;从零构建系统化知识体系》 &#x1f525; &#x1f6e0;️ 专栏简介&#xff1a; 这是一个以工业级开发标准打造的 PHP 全栈技术专栏&#xff0c;涵盖语法精粹、异步编程、Zend引擎原理、框架源码、高并发架构等全维度知识体系…...

C#简易Modbus从站仿真器

C#使用NModbus库&#xff0c;编写从站仿真器&#xff0c;支持Modbus TCP访问&#xff0c;支持多个从站地址和动态启用/停用从站&#xff08;模拟离线&#xff09;&#xff0c;支持数据变化&#xff0c;可以很方便实现&#xff0c;最终效果如图所示。 项目采用.net framework 4.…...

Error parsing column 10 (YingShou=-99.5 - Double) dapper sqlite

在使用sqlite 调取 dapper的时候出现这个问题提示&#xff1a; 原因是 在 sqlite表中设定的字段类型是 decimel而在C#的字段属性也是decimel&#xff0c;结果解析F负数 小数的时候出现这个错误提示&#xff1a; 解决办法&#xff1a;使用默认的sqlite的字段类型来填入 REAL描述…...

Spring AI系列——使用大模型对文本进行内容总结归纳分析

一、技术原理与架构设计 1. 技术原理 本项目基于 Spring AI Alibaba 框架&#xff0c;结合 DashScope 大模型服务 实现文本内容的自动摘要和结构化输出。核心原理如下&#xff1a; 文档解析&#xff1a; 使用 TikaDocumentReader 解析上传的文件&#xff08;如 PDF、Word 等&…...