QT中基于TCP的网络通信

news/2024/5/21 13:14:27

QT中基于TCP的网络通信

  • QTcpServer
    • 公共成员函数
    • 信号
  • QTcpSocket
    • 公共成员函数
    • 信号
  • 通信流程
    • 服务器端
      • 通信流程
      • 代码
    • 客户端
      • 通信流程
      • 代码
  • 多线程网络通信
    • SendFileClient
    • SendFileServer

使用Qt提供的类进行基于TCP的套接字通信需要用到两个类:

QTcpServer:服务器类,用于监听客户端连接以及和客户端建立连接。
QTcpSocket:通信的套接字类,客户端、服务器端都需要使用。
这两个套接字通信类都属于网络模块network。

QTcpServer

QTcpServer类 用于监听客户端连接以及和客户端建立连接,在使用之前先介绍一下这个类提供的一些常用API函数

公共成员函数

构造函数

QTcpServer::QTcpServer(QObject *parent = Q_NULLPTR);

给监听的套接字设置监听

bool QTcpServer::listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0);
// 判断当前对象是否在监听, 是返回true,没有监听返回false
bool QTcpServer::isListening() const;
// 如果当前对象正在监听返回监听的服务器地址信息, 否则返回 QHostAddress::Null
QHostAddress QTcpServer::serverAddress() const;
// 如果服务器正在侦听连接,则返回服务器的端口; 否则返回0
quint16 QTcpServer::serverPort() const

参数:
address:通过类QHostAddress可以封装IPv4、IPv6格式的IP地址,QHostAddress::Any表示自动绑定
port:如果指定为0表示随机绑定一个可用端口。
返回值:绑定成功返回true,失败返回false

QTcpSocket *QTcpServer::nextPendingConnection();

得到和客户端建立连接之后用于通信的QTcpSocket套接字对象,它是QTcpServer的一个子对象,当QTcpServer对象析构的时候会自动析构这个子对象,当然也可自己手动析构,建议用完之后自己手动析构这个通信的QTcpSocket对象。

bool QTcpServer::waitForNewConnection(int msec = 0, bool *timedOut = Q_NULLPTR);

阻塞等待客户端发起的连接请求,不推荐在单线程程序中使用,建议使用非阻塞方式处理新连接,即使用信号 newConnection() 。

参数:
msec:指定阻塞的最大时长,单位为毫秒(ms)
timeout:传出参数,如果操作超时timeout为true,没有超时timeout为false

信号

当接受新连接导致错误时,将发射如下信号。socketError参数描述了发生的错误相关的信息。

[signal] void QTcpServer::acceptError(QAbstractSocket::SocketError socketError);

每次有新连接可用时都会发出 newConnection() 信号。

[signal] void QTcpServer::newConnection();

QTcpSocket

QTcpSocket是一个套接字通信类,不管是客户端还是服务器端都需要使用。在Qt中发送和接收数据也属于IO操作(网络IO),先来看一下这个类的继承关系:

在这里插入图片描述

公共成员函数

构造函数

QTcpSocket::QTcpSocket(QObject *parent = Q_NULLPTR);

连接服务器,需要指定服务器端绑定的IP和端口信息。

[virtual] void QAbstractSocket::connectToHost(const QString &hostName, quint16 port, OpenMode openMode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol);[virtual] void QAbstractSocket::connectToHost(const QHostAddress &address, quint16 port, OpenMode openMode = ReadWrite);

在Qt中不管调用读操作函数接收数据,还是调用写函数发送数据,操作的对象都是本地的由Qt框架维护的一块内存。因此,调用了发送函数数据不一定会马上被发送到网络中,调用了接收函数也不是直接从网络中接收数据,关于底层的相关操作是不需要使用者来维护的。

接收数据

// 指定可接收的最大字节数 maxSize 的数据到指针 data 指向的内存中
qint64 QIODevice::read(char *data, qint64 maxSize);
// 指定可接收的最大字节数 maxSize,返回接收的字符串
QByteArray QIODevice::read(qint64 maxSize);
// 将当前可用操作数据全部读出,通过返回值返回读出的字符串
QByteArray QIODevice::readAll();

发送数据

// 发送指针 data 指向的内存中的 maxSize 个字节的数据
qint64 QIODevice::write(const char *data, qint64 maxSize);
// 发送指针 data 指向的内存中的数据,字符串以 \0 作为结束标记
qint64 QIODevice::write(const char *data);
// 发送参数指定的字符串
qint64 QIODevice::write(const QByteArray &byteArray);

信号

在使用QTcpSocket进行套接字通信的过程中,如果该类对象发射出readyRead()信号,说明对端发送的数据达到了,之后就可以调用 read 函数接收数据了。

[signal] void QIODevice::readyRead();

调用connectToHost()函数并成功建立连接之后发出connected()信号。

[signal] void QAbstractSocket::connected();

在套接字断开连接时发出disconnected()信号。

[signal] void QAbstractSocket::disconnected();

通信流程

在这里插入图片描述

服务器端

通信流程

  1. 创建套接字服务器QTcpServer对象
  2. 通过QTcpServer对象设置监听,即:QTcpServer::listen()
  3. 基于QTcpServer::newConnection()信号检测是否有新的客户端连接
  4. 如果有新的客户端连接调用QTcpSocket
  5. *QTcpServer::nextPendingConnection()得到通信的套接字对象
  6. 使用通信的套接字对象QTcpSocket和客户端进行通信

代码

服务器端的窗口界面如下图所示:
在这里插入图片描述

QtServer.pro文件

在这里插入图片描述

mainwindow.h文件

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QTcpServer>
#include <QTcpSocket>
#include <QLabel>QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void on_setListen_clicked();void on_sendMsg_clicked();private:Ui::MainWindow *ui;QTcpServer* m_s;QTcpSocket* m_tcp;QLabel* m_status;
};
#endif // MAINWINDOW_H

main.cpp文件

#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);MainWindow w;w.show();return a.exec();
}

mainwindow.cpp文件

#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);ui->port->setText("8000"); //先设置一个端口号setWindowTitle("服务器");//创建监听的服务器对象m_s = new QTcpServer(this); //指定父对象,不需要再去管内存的释放//等待客户端链接,连接上会发送一个信号newConnectionconnect(m_s,&QTcpServer::newConnection,this,[=](){m_tcp = m_s->nextPendingConnection(); //得到可供通讯的套接字对象m_status->setPixmap(QPixmap(":/connect.png").scaled(20,20)); //更改链接状态//检测是否可以接收数据connect(m_tcp,&QTcpSocket::readyRead,this,[=](){QByteArray data = m_tcp->readAll(); //全部读出来ui->record->append("客户端say: " + data);  //显示在历史记录框中});//对端断开链接时会,TcpSocket会发送一个disconnect信号connect(m_tcp,&QTcpSocket::disconnected,this,[=](){m_tcp->close(); //关闭套接字m_tcp->deleteLater(); //释放m_tcpm_status->setPixmap(QPixmap(":/disconnect.png").scaled(20,20)); //更改链接状态});});//状态栏m_status = new QLabel;//给标签设置图片m_status->setPixmap(QPixmap(":/disconnect.png").scaled(20,20));  //scaled设置图片大小//将标签设置到状态栏中ui->statusbar->addWidget(new QLabel("连接状态: "));ui->statusbar->addWidget(m_status);
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::on_setListen_clicked()
{unsigned short port = ui->port->text().toUShort();m_s->listen(QHostAddress::Any,port); //开始监听ui->setListen->setDisabled(true);  //监听之后设置为不可用状态
}void MainWindow::on_sendMsg_clicked()
{QString msg = ui->msg->toPlainText(); //以纯文本的方式把数据读出来m_tcp->write(msg.toUtf8());ui->record->append("服务器say: " + msg);  //显示在历史记录框中
}

mainwindow.ui文件
在这里插入图片描述

客户端

通信流程

  1. 创建通信的套接字类QTcpSocket对象
  2. 使用服务器端绑定的IP和端口连接服务器QAbstractSocket::connectToHost()
  3. 使用QTcpSocket对象和服务器进行通信

代码

客户端的窗口界面如下图所示:
在这里插入图片描述

QtClient.pro文件
在这里插入图片描述
mainwindow.h文件

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QTcpSocket>
#include <QLabel>QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void on_sendMsg_clicked();void on_connect_clicked();void on_disconnect_clicked();private:Ui::MainWindow *ui;QTcpSocket* m_tcp;QLabel* m_status;
};
#endif // MAINWINDOW_H

main.cpp文件

#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);MainWindow w;w.show();return a.exec();
}

mainwindow.cpp文件

#include "mainwindow.h"
#include "ui_mainwindow.h"#include <QHostAddress>MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);ui->port->setText("8000"); //先设置一个端口号ui->ip->setText("127.0.0.1"); //设置本地循环ipsetWindowTitle("客户端");ui->disconnect->setDisabled(true);//断开连接按钮不可用//创建监听的服务器对象m_tcp = new QTcpSocket(this); //指定父对象,不需要再去管内存的释放//检测是否可以接受数据 当 m_tcp 发送给出readyRead信号,就说明有信号到达了connect(m_tcp,&QTcpSocket::readyRead,this,[=](){QByteArray data = m_tcp->readAll(); //全部读出来ui->record->append("服务器say: " + data);  //显示在历史记录框中});//对端断开链接时会,TcpSocket会发送一个disconnect信号connect(m_tcp,&QTcpSocket::disconnected,this,[=](){m_tcp->close(); //关闭套接字//m_tcp->deleteLater(); // 指定了父对象,不需要手动释放 m_tcpm_status->setPixmap(QPixmap(":/disconnect.png").scaled(20,20)); //更改链接状态ui->record->append("服务器已经和客户端断开了连接...");ui->connect->setDisabled(false); //连接按钮可用ui->disconnect->setEnabled(false); //断开连接按钮不可用});//当 m_tcp 发送一个 connected 信号后,就说明已经连接上服务器connect(m_tcp,&QTcpSocket::connected,this,[=](){m_status->setPixmap(QPixmap(":/connect.png").scaled(20,20));  //scaled设置图片大小ui->record->append("已经成功连接到了服务器...");ui->connect->setDisabled(true); //连接按钮不可用ui->disconnect->setEnabled(true); //断开连接按钮可用});//状态栏m_status = new QLabel;//给标签设置图片m_status->setPixmap(QPixmap(":/disconnect.png").scaled(20,20));  //scaled设置图片大小//将标签设置到状态栏中ui->statusbar->addWidget(new QLabel("连接状态: "));ui->statusbar->addWidget(m_status);
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::on_sendMsg_clicked()
{QString msg = ui->msg->toPlainText(); //以纯文本的方式把数据读出来m_tcp->write(msg.toUtf8());ui->record->append("客户端say: " + msg);  //显示在历史记录框中
}void MainWindow::on_connect_clicked()
{QString ip = ui->ip->text();unsigned short port = ui->port->text().toUShort();m_tcp->connectToHost(QHostAddress(ip),port);
}void MainWindow::on_disconnect_clicked()
{m_tcp->close();ui->connect->setDisabled(false);ui->disconnect->setEnabled(false);
}

mainwindow.ui文件
在这里插入图片描述

多线程网络通信

客户端通过子线程发送文件,服务器通过子线程接收文件。

通信界面
在这里插入图片描述

SendFileClient

在这里插入图片描述
mainwindow.h文件

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();signals:
void startConnect(unsigned short,QString ip);
void sendFile(QString path);private slots:void on_connectServer_clicked();void on_selFile_clicked();void on_sendFile_clicked();private:Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

sendfile.h文件

#ifndef SENDFILE_H
#define SENDFILE_H#include <QObject>
#include <QTcpSocket>class SendFile : public QObject
{Q_OBJECT
public:explicit SendFile(QObject *parent = nullptr);//连接服务器void connectServer(unsigned short port,QString ip);//发送文件void sendFile(QString path);signals:void connectOk();void gameOver();void CurPercent(int num);
private:QTcpSocket* m_tcp;};#endif // SENDFILE_H

main.cpp文件

#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);MainWindow w;w.show();return a.exec();
}

mainwindow.cpp文件

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QThread>
#include "sendfile.h"
#include <QFileDialog>
#include <QDebug>MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);setFixedSize(400,300);setWindowTitle("客户端");qDebug() << "主线程: " << QThread::currentThread();ui->ip->setText("127.0.0.1");ui->port->setText("8000");ui->progressBar->setRange(0,100); //进度条设置范围ui->progressBar->setValue(0); //进度设置初始值//创建线程对象QThread* t = new QThread;//创建任务对象SendFile* worker = new SendFile;worker->moveToThread(t);  //worker对象就会在 线程 t 里面执行connect(this,&MainWindow::sendFile,worker,&SendFile::sendFile);connect(this,&MainWindow::startConnect,worker,&SendFile::connectServer);//处理子线程发送的信号connect(worker,&SendFile::connectOk,this,[=](){QMessageBox::information(this,"连接服务器","已经成功连接了服务器");});connect(worker,&SendFile::gameOver,this,[=](){//资源释放t->quit();t->wait();worker->deleteLater();t->deleteLater();});//接受子线程发送的数据,更新进度条connect(worker,&SendFile::CurPercent,ui->progressBar,&QProgressBar::setValue);t->start(); //启动线程}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::on_connectServer_clicked()
{QString ip = ui->ip->text(); //获取ipunsigned short port = ui->port->text().toUShort();emit startConnect(port,ip); //发送连接信号
}void MainWindow::on_selFile_clicked()
{QString path = QFileDialog::getOpenFileName(); //获取文件路径if(path.isEmpty()){QMessageBox::warning(this,"打开文件","选择的文件路径不能为空!");return;}ui->filePath->setText(path);
}void MainWindow::on_sendFile_clicked()
{emit sendFile(ui->filePath->text());
}

sendfile.cpp文件

#include "sendfile.h"#include <QFile>
#include <QFileInfo>
#include <QHostAddress>
#include <QDebug>
#include <QThread>SendFile::SendFile(QObject *parent) : QObject(parent)
{}void SendFile::connectServer(unsigned short port, QString ip)
{qDebug() << "连接服务器线程: " << QThread::currentThread();m_tcp = new QTcpSocket;m_tcp->connectToHost(QHostAddress(ip),port);//当m_tcp发送connected信号后,表示已经连接成功了connect(m_tcp,&QTcpSocket::connected,this,&SendFile::connectOk);//当m_tcp发送disconnected信号后,表示服务器断开连接了connect(m_tcp,&QTcpSocket::disconnected,this,[=](){m_tcp->close();m_tcp->deleteLater();//发送信号给主线程,告诉主线程服务器已经断开连接emit gameOver();});
}void SendFile::sendFile(QString path)
{qDebug() << "发送文件线程: " << QThread::currentThread();QFile file(path);QFileInfo info(path);int fileSize = info.size(); //求文件大小file.open(QFile::ReadOnly); //只读形式while(!file.atEnd()){//第一次循环的时候,要把文件大小传送过去static int num = 0;if(num==0){m_tcp->write((char*)&fileSize, 4);}QByteArray line = file.readLine(); //一行一行读num += line.size();int percent = (num*100 / fileSize);emit CurPercent(percent); //更新传送文件的百分比m_tcp->write(line); //将数据发送给服务器}
}

SendFileServer

在这里插入图片描述
mainwindow.h文件

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QTcpServer>
#include "mytcpserver.h"QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void on_setListen_clicked();private:Ui::MainWindow *ui;MyTcpServer* m_s;
};
#endif // MAINWINDOW_H

mytcpserver.h文件

#ifndef MYTCPSERVER_H
#define MYTCPSERVER_H#include <QTcpServer>class MyTcpServer : public QTcpServer
{Q_OBJECT
public:explicit MyTcpServer(QObject *parent = nullptr);protected:virtual void incomingConnection(qintptr socketDescriptor) override;
signals:void newDescriptor(qintptr sock);};#endif // MYTCPSERVER_H

recvfile.h文件

#ifndef RECVFILE_H
#define RECVFILE_H#include <QThread>
#include <QTcpSocket>class RecvFile : public QThread
{Q_OBJECT
public:explicit RecvFile(qintptr sock,QObject *parent = nullptr);protected:void run() override;
private:QTcpSocket* m_tcp;
signals:void over();
};#endif // RECVFILE_H

main.cpp文件

#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);MainWindow w;w.show();return a.exec();
}

mainwindow.cpp文件

#include "mainwindow.h"
#include "ui_mainwindow.h"#include <QMessageBox>
#include <QTcpSocket>
#include "recvfile.h"
#include <QDebug>MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);setFixedSize(400,300);setWindowTitle("服务器");qDebug()<<"服务器主线程: "<<QThread::currentThread();m_s = new MyTcpServer(this);//检测是否有连接信号connect(m_s,&MyTcpServer::newDescriptor,this,[=](qintptr sock){// QTcpSocket* tcp = m_s->nextPendingConnection(); //得到用于通讯的Socket对象//创建子线程RecvFile* subThread  =new RecvFile(sock);subThread->start(); //启动子线程//接收子线程信号connect(subThread,&RecvFile::over,this,[=](){subThread->exit();subThread->wait();subThread->deleteLater();QMessageBox::information(this,"文件接收","文件接收完毕!!!");});});}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::on_setListen_clicked()
{unsigned short port = ui->port->text().toUShort();m_s->listen(QHostAddress::Any,port);
}

mytcpserver.cpp文件

#include "mytcpserver.h"MyTcpServer::MyTcpServer(QObject *parent) : QTcpServer(parent)
{}//当客户端发起新的连接,就会被自动调用
void MyTcpServer::incomingConnection(qintptr socketDescriptor)
{//不能在子线程里面直接使用主线程定义的套接字对象,自己在子线程中定义一个emit newDescriptor(socketDescriptor);
}

recvfile.cpp文件

#include "recvfile.h"
#include <QFile>
#include <QDebug>RecvFile::RecvFile(qintptr sock,QObject *parent) : QThread(parent)
{m_tcp = new QTcpSocket(this);m_tcp->setSocketDescriptor(sock);
}void RecvFile::run()
{qDebug() << "服务器子线程: " << QThread::currentThread();QFile* file = new QFile("recv.txt");file->open(QFile::WriteOnly);//接受数据connect(m_tcp,&QTcpSocket::readyRead,this,[=](){static int count = 0;static int total = 0;if(count ==0) //第一次接收,把文件大小接收过来{m_tcp->read((char*)&total,4); //接收4个字节}//读剩余的数据QByteArray all = m_tcp->readAll();count += all.size();file->write(all);//判断数据是否接收完毕if(count==total){m_tcp->close();m_tcp->deleteLater();file->close();file->deleteLater();//发送信号告诉子线程数据已经接收完emit over();}});//进入事件循环exec(); //保证子线程不退出
}

http://www.mrgr.cn/p/43114313

相关文章

SQL SERVER 从入门到精通 第5版 第三篇 高级应用 第12章 游标的使用 读书笔记

第十二章 游标的使用>.游标的概述游标是一种数据库对象,用于在SQL中处理(SELECT的)查询结果集。它允许逐行地访问查询结果集的数据,以进行一系列操作,如更新、删除或插入数据。游标通常用于存储过程或触发器中,用于对数据进行逐行处理。通过游标,可以实现对结果集的逐行…

【Linux】管道

思维导图 学习内容 进程间通信的一些知识点&#xff1a;是什么、为什么和怎么办&#xff1f;&#xff1f;之后就是理解管道中的匿名管道的一些知识点&#xff1a;会创建匿名管道、匿名管道的四种情况……最后&#xff0c;就是进程池的代码编写&#xff0c;也是最难的一部分。 …

完美国际单机debug版本

完美国际单机debug版本 更新版本号:无 下载地址: https://files.cnblogs.com/files/xe2011/debug_wmGj.rar说明这只能用在个人单机版本的游戏上使用, 不能在官方完美世界,完美世界2上使用联系方式 微信:roman_2015【更新记录】 2024年1月28日 15:14:33 [*]修复了城战会掉线…

国产麒麟系统下打包electron+vue项目(AppImage、deb)

需要用到的一些依赖包、安装包以及更详细的打包方法word以及麒麟官网给出的文档都已放网盘&#xff0c;链接在文章最后&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&a…

计算机网络 备查

OSI 七层模型 七层模型协议各层实现的功能 简要 详细 TCP/IP协议 组成 1.传输层协议 TCP 2.网络层协议 IP 协议数据单元&#xff08;PDU&#xff09;和 封装 数据收发过程 数据发送过程 1. 2.终端用户生成数据 3.数据被分段&#xff0c;并加上TCP头 4.网络层添加IP地址信息…

SSRF

SSRF漏洞 一、概念 什么是SSRF漏洞 ​ SSRF(Server-Side Request Forgery,服务器请求伪造)是一种由攻击者构造请求,由服务端发起请求的安全漏洞,一般情况下,SSRF攻击的目标是外网无法访问的内网系统(正因为请求时由服务端发起的,所以服务端能请求到与自身相连而与外网隔绝…

毅四捕Go设计模式笔记——命令模式

命令模式&#xff08;Command Pattern&#xff09; 为了解决什么问题&#xff1f; 命令模式的目的是将请求发起者和请求执行者解耦&#xff0c;使得请求的发起者不需要知道具体的执行者是谁&#xff0c;也不需要知道执行的具体过程&#xff0c;只需要发送请求即可。 通过使用…

java 远程debug

java -agentlib:jdwptransportdt_socket,servery,suspendn,address50050 -Xmx1536m -XX:HeapDumpOnOutOfMemoryError -XX:HeapDumpPath./ -jar ${JAR_NAME} >/dev/null 2>&1 &参数说明 -agentlib:jdwptransportdt_socket,servery,suspendn,address50050: 这个参数…

解决RTC内核驱动的问题bm8563

常用pcf-8563 , 国产平替BM8563(驱动管脚一致)&#xff1b; 实时时钟是很常用的一个外设&#xff0c;通过实时时钟我们就可以知道年、月、日和时间等信息。 因此在需要记录时间的场合就需要实时时钟&#xff0c;可以使用专用的实时时钟芯片来完成此功能 RTC 设备驱动是一个标准…

深入理解正则表达式:从入门到精通

title: 深入理解正则表达式:从入门到精通 date: 2024/4/30 18:37:21 updated: 2024/4/30 18:37:21 tags:正则 Python 文本分析 日志挖掘 数据清洗 模式匹配 工具推荐第一章:正则表达式入门 介绍正则表达式的基本概念和语法 正则表达式是一种用于描述字符串模式的表达式,由普…

怎么给程序员定 KPI ?原则和最佳KPI

为了避免依赖直觉而导致的效率和执行问题,企业应该设置清晰的目标和高级策略来衡量软件开发过程的生产力和效率的关键绩效指标(KPI),并确保这些KPI与他们目标的质量相匹配。研究表明,相较于传统办公室环境,远程工作团队的效率更高。这引出了一个问题:远程软件工程师的效…

OceanBase开发者大会实录 - 阳振坤:云时代的数据库

本文来自2024 OceanBase开发者大会&#xff0c;OceanBase 首席科学家阳振坤的演讲实录——《云时代的数据库》。完整视频回看&#xff0c;请点击这里 >> 在去年的开发者大会中&#xff0c;我跟大家分享了我对数据库产品和技术一些看法&#xff0c;包括单机分布式一体化&…

不同技术实现鼠标滚动图片的放大缩小

摘要&#xff1a; 最近弄PC端的需求时&#xff0c;要求在layui技术下实现鼠标滚动图片的放大缩小的功能&#xff01;下面来总结一下不同框架剩下这功能&#xff01; layui: 看了一下layui文档&#xff0c;其实这有自带的组件的&#xff01;但是又版本要求的!并且layui的官方文档…

Prometheus监控mongo

安装mongo插件123456789yum -y install glidegit clone git@github.com:dcu/mongodb_exporter.git $GOPATH/src/github.com/dcu/mongodb_exporter也可以去github上,下载源码,在编译安装cd $GOPATH/src/github.com/dcu/mongodb_exportermake build./mongodb_exporter -h注意:…

软考-信息系统项目管理师-论文技术架构模板(60天备考第26天)

分享一段信息系统项目管理师论文项目技术架构描述的万能模板&#xff0c;供大家参考。距离考试还有二十八天&#xff0c;如果论文写不好的可以加微进论文指导群学习论文写作。 该系统前端基于Vue开发&#xff0c;后端基于java开发&#xff0c;前后端分离部署。整体采用B/S架构&…

服务器(AIX、Linux、UNIX)性能监视器工具【nmon】使用介绍

目录 ■nmon简介 1.安装 2.使用简介 3.使用&#xff08;具体使用的例子【CPU】【内存】&#xff09; 4.采集数据 5.查看log&#xff08;根据结果&#xff0c;生成报表&#xff09; 6.分析结果 7.设定任务计划&#xff08;Cron&#xff09;&#xff0c;每日执行 ■nmo…

新华三李玉涛:智算网络是解决AI算力需求的关键

近年来&#xff0c;人工智能领域呈现爆发式增长&#xff0c;尤其在OpenAI、文心一言等大模型的不断推出&#xff0c;参数规模实现了飞跃式增长。同时&#xff0c;Character AI、谷歌Bard等应用已经逐渐渗透至日常生活和工作当中&#xff0c;越来越多的人开始借助AIGC工具来提升…

Prometheus监控MongoDB数据库

监控环境:Prometheus 数据库:MongoDB 3.4.6 集群,3个节点 监控工具:mongodb_exporter1、创建Mongodb监控可读账号 mongodb admin 库中执行use admin db.createUser({ user: "prometheus",pwd: "prometheus",roles: [{ role: "read", db: &q…

若依前后端部署系统--详细附图

一、后端部署 1、在ruoyi项目的Maven中的生命周期下双击package.bat打包Web工程&#xff0c;生成jar包文件。 提示打包成功 2、多模块版本会生成在ruoyi/ruoyi-admin模块下target文件夹,我们打开目录ruoyi-admin/taget&#xff0c;打开cmd&#xff0c;运行java -jar jar包名称…