prepare to test 10 million peer s/c.
24
test/Test10millionPeerClient/AppRoot/skin/default.qss
Normal file
@ -0,0 +1,24 @@
|
||||
/*spinbox 抬起样式*/
|
||||
QTimeEdit::up-button,QDoubleSpinBox::up-button,QSpinBox::up-button {
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:right;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
QTimeEdit::down-button,QDoubleSpinBox::down-button,QSpinBox::down-button {
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:left;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
/*按钮按下样式*/
|
||||
QTimeEdit::up-button:pressed,QDoubleSpinBox::up-button:pressed,QSpinBox::up-button:pressed{
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:right;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
QTimeEdit::down-button:pressed,QDoubleSpinBox::down-button:pressed,QSpinBox::down-button:pressed,QSpinBox::down-button:pressed{
|
||||
subcontrol-position:left;
|
||||
width: 12px;
|
||||
}
|
72
test/Test10millionPeerClient/Test10millionPeerClient.pro
Normal file
@ -0,0 +1,72 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2018-10-06T08:16:10
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = Test10millionPeerClient
|
||||
TEMPLATE = app
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
|
||||
SOURCES += \
|
||||
test10millionpeerclientprotocol.cpp
|
||||
HEADERS += \
|
||||
test10millionpeerclientprotocol.h
|
||||
|
||||
include($${PWD}/../../multi-link/add_base_manager.pri)
|
||||
|
||||
#-------------------------------------------------
|
||||
#用户工程配置
|
||||
#-------------------------------------------------
|
||||
add_version(1,0,0,0)
|
||||
add_deploy()
|
||||
add_deploy_config($${PWD}/AppRoot)
|
||||
add_dependent_manager(QQt)
|
||||
system(touch main.cpp)
|
||||
|
||||
#-------------------------------------------------
|
||||
#用户工程配置
|
||||
#-------------------------------------------------
|
||||
equals(QSYS_PRIVATE, macOS) {
|
||||
CONFIG += app_bundle
|
||||
}
|
||||
|
||||
contains(QSYS_PRIVATE, Android|AndroidX86) {
|
||||
CONFIG += mobility
|
||||
MOBILITY =
|
||||
DISTFILES += \
|
||||
android/AndroidManifest.xml
|
||||
|
||||
ANDROID_PACKAGE_SOURCE_DIR = $${PWD}/android
|
||||
}
|
||||
|
||||
message ($${TARGET} config $${CONFIG})
|
||||
message ($${TARGET} DEFINE $${DEFINES})
|
||||
message ($${TARGET} prelink $${QMAKE_PRE_LINK})
|
||||
message ($${TARGET} postlink $${QMAKE_POST_LINK})
|
89
test/Test10millionPeerClient/android/AndroidManifest.xml
Normal file
@ -0,0 +1,89 @@
|
||||
<?xml version="1.0"?>
|
||||
<manifest package="org.qtproject.example.test10millionpeerclient" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
|
||||
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="Test10millionPeerClient" android:icon="@drawable/icon">
|
||||
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="Test10millionPeerClient" android:screenOrientation="unspecified" android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Application arguments -->
|
||||
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
|
||||
<!-- Application arguments -->
|
||||
|
||||
<meta-data android:name="android.app.lib_name" android:value="Test10millionPeerClient"/>
|
||||
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
|
||||
<meta-data android:name="android.app.repository" android:value="default"/>
|
||||
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
|
||||
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
|
||||
<!-- Deploy Qt libs as part of package -->
|
||||
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="1"/>
|
||||
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
|
||||
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
|
||||
<!-- Run with local libs -->
|
||||
<meta-data android:name="android.app.use_local_qt_libs" android:value="1"/>
|
||||
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
|
||||
<meta-data android:name="android.app.load_local_libs" android:value="plugins/platforms/android/libqtforandroid.so"/>
|
||||
<meta-data android:name="android.app.load_local_jars" android:value="jar/QtAndroid.jar:jar/QtAndroid-bundled.jar"/>
|
||||
<meta-data android:name="android.app.static_init_classes" android:value=""/>
|
||||
<!-- Messages maps -->
|
||||
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
|
||||
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
|
||||
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
|
||||
<!-- Messages maps -->
|
||||
|
||||
<!-- Splash screen -->
|
||||
<!-- meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/ -->
|
||||
<!-- meta-data android:name="android.app.splash_screen_sticky" android:value="true"/ -->
|
||||
<!-- Splash screen -->
|
||||
|
||||
<!-- Background running -->
|
||||
<!-- Warning: changing this value to true may cause unexpected crashes if the
|
||||
application still try to draw after
|
||||
"applicationStateChanged(Qt::ApplicationSuspended)"
|
||||
signal is sent! -->
|
||||
<meta-data android:name="android.app.background_running" android:value="false"/>
|
||||
<!-- Background running -->
|
||||
|
||||
<!-- auto screen scale factor -->
|
||||
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="false"/>
|
||||
<!-- auto screen scale factor -->
|
||||
|
||||
<!-- extract android style -->
|
||||
<!-- available android:values :
|
||||
* full - useful QWidget & Quick Controls 1 apps
|
||||
* minimal - useful for Quick Controls 2 apps, it is much faster than "full"
|
||||
* none - useful for apps that don't use any of the above Qt modules
|
||||
-->
|
||||
<meta-data android:name="android.app.extract_android_style" android:value="full"/>
|
||||
<!-- extract android style -->
|
||||
</activity>
|
||||
|
||||
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
|
||||
|
||||
</application>
|
||||
|
||||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16"/>
|
||||
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
|
||||
|
||||
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
|
||||
Remove the comment if you do not require these default permissions. -->
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
|
||||
Remove the comment if you do not require these default features. -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<!-- %%INSERT_PERMISSIONS -->
|
||||
<!-- %%INSERT_FEATURES -->
|
||||
<uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
|
||||
</manifest>
|
After Width: | Height: | Size: 13 KiB |
BIN
test/Test10millionPeerClient/android/res/drawable-hdpi/icon.png
Normal file
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 3.5 KiB |
BIN
test/Test10millionPeerClient/android/res/drawable-ldpi/icon.png
Normal file
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 6.0 KiB |
BIN
test/Test10millionPeerClient/android/res/drawable-mdpi/icon.png
Normal file
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 82 KiB |
11
test/Test10millionPeerClient/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QQtApplication>
|
||||
|
||||
int main ( int argc, char* argv[] )
|
||||
{
|
||||
QQtApplication a ( argc, argv );
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
14
test/Test10millionPeerClient/mainwindow.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
22
test/Test10millionPeerClient/mainwindow.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
40
test/Test10millionPeerClient/mainwindow.ui
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Test10millionPeerClient</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget"/>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
138
test/Test10millionPeerClient/test10millionpeerclientprotocol.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
#include "test10millionpeerclientprotocol.h"
|
||||
#include <qqtapplication.h>
|
||||
quint32 gnum = 0;
|
||||
QMutex mutex ( QMutex::NonRecursive );
|
||||
|
||||
QDebug& operator << ( QDebug& dbg, const Test10millionPeerClientMessage& msg )
|
||||
{
|
||||
//这里打印一下,报文里面到底有什么信息,
|
||||
//一般到这里的,都是被解析好的message。
|
||||
|
||||
dbg.nospace() << "{" << hex << msg.size() << "}";
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
QQtTcpClient* Test10millionPeerClientInstance ( Test10millionPeerClientProtocol*& protocol, QObject* parent )
|
||||
{
|
||||
static Test10millionPeerClientProtocol* p0 = NULL;
|
||||
if ( !p0 )
|
||||
{
|
||||
p0 = new Test10millionPeerClientProtocol ( parent );
|
||||
}
|
||||
protocol = p0;
|
||||
|
||||
static QQtTcpClient* s0 = NULL;
|
||||
if ( !s0 )
|
||||
{
|
||||
s0 = new QQtTcpClient ( parent );
|
||||
s0->installProtocol ( p0 );
|
||||
//s0->setServer
|
||||
//s0->sendConnectToHost();
|
||||
}
|
||||
|
||||
for ( int i = 0; i < 100000; i++ )
|
||||
{
|
||||
Test10millionPeerClientProtocol* p1 = new Test10millionPeerClientProtocol ( parent );
|
||||
QQtTcpClient* s1 = new QQtTcpClient ( parent );
|
||||
s1->installProtocol ( p1 );
|
||||
s1->setServerIPAddress ( "192.168.3.103" );
|
||||
s1->sendConnectToHost();
|
||||
s1->waitForConnected();
|
||||
p1->sendCommand1();
|
||||
QQtApplication::processEvents();
|
||||
}
|
||||
|
||||
return s0;
|
||||
}
|
||||
|
||||
Test10millionPeerClientProtocol::Test10millionPeerClientProtocol ( QObject* parent )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Test10millionPeerClientProtocol::~Test10millionPeerClientProtocol()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Test10millionPeerClientProtocol::recvCommand1 ( const Test10millionPeerClientMessage& msg )
|
||||
{
|
||||
//what do you want to do?
|
||||
pline() << this << msg.data();
|
||||
sendCommand2();
|
||||
mutex.lock();
|
||||
gnum ++;
|
||||
mutex.unlock();
|
||||
pline() << "protocol " << gnum << "complete.";
|
||||
}
|
||||
|
||||
void Test10millionPeerClientProtocol::recvCommand2 ( const Test10millionPeerClientMessage& msg )
|
||||
{
|
||||
//what do you want to do?
|
||||
}
|
||||
|
||||
void Test10millionPeerClientProtocol::sendCommand1()
|
||||
{
|
||||
//what do you want to do?
|
||||
Test10millionPeerClientMessage msg;
|
||||
msg.cmd() = 0x0a;
|
||||
msg.data() = 0x00;
|
||||
QByteArray l;
|
||||
msg.packer ( l );
|
||||
write ( l );
|
||||
}
|
||||
|
||||
void Test10millionPeerClientProtocol::sendCommand2()
|
||||
{
|
||||
Test10millionPeerClientMessage msg;
|
||||
msg.cmd() = 0x0b;
|
||||
msg.data() = 0x01;
|
||||
QByteArray l;
|
||||
msg.packer ( l );
|
||||
write ( l );
|
||||
}
|
||||
|
||||
quint16 Test10millionPeerClientProtocol::minlength()
|
||||
{
|
||||
return 0x0a;
|
||||
}
|
||||
|
||||
quint16 Test10millionPeerClientProtocol::maxlength()
|
||||
{
|
||||
return 0x07FF;
|
||||
}
|
||||
|
||||
quint16 Test10millionPeerClientProtocol::splitter ( const QByteArray& l ) //stream
|
||||
{
|
||||
QByteArray s0 = l.left ( 1 );
|
||||
quint8 size = 0;
|
||||
s0 >> size;
|
||||
return size;
|
||||
}
|
||||
|
||||
bool Test10millionPeerClientProtocol::dispatcher ( const QByteArray& m ) //message
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
Test10millionPeerClientMessage qMsg;
|
||||
qMsg.parser ( m );
|
||||
pline() << qMsg;
|
||||
|
||||
switch ( qMsg.cmd() )
|
||||
{
|
||||
case 0x0a://protocol command 1
|
||||
recvCommand1 ( qMsg );
|
||||
break;
|
||||
|
||||
case 0x0b://protocol command 2
|
||||
recvCommand2 ( qMsg );
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = false;
|
||||
pline() << "receive unknown command:" << hex << qMsg.cmd();
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
#ifndef TEST10MILLIONPEERCLIENTPROTOCOL_H
|
||||
#define TEST10MILLIONPEERCLIENTPROTOCOL_H
|
||||
|
||||
#include <qqtmessage.h>
|
||||
#include <qqtprotocol.h>
|
||||
#include <qqttcpclient.h>
|
||||
|
||||
class Test10millionPeerClientMessage : public QQtMessage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Test10millionPeerClientMessage ( QObject* parent = nullptr ) {
|
||||
mSize = 0x03;//报文定长
|
||||
}
|
||||
~Test10millionPeerClientMessage() {
|
||||
|
||||
}
|
||||
|
||||
quint8& size() { return mSize; }
|
||||
const quint8& size() const { return mSize; }
|
||||
quint8& cmd() { return mCmd; }
|
||||
const quint8& cmd() const { return mCmd; }
|
||||
quint8& data() { return mData; }
|
||||
const quint8& data() const { return mData; }
|
||||
|
||||
private:
|
||||
//格式
|
||||
//|quint8 size|quint8 cmd|quint8 data|
|
||||
quint8 mSize;
|
||||
quint8 mCmd;
|
||||
quint8 mData;
|
||||
|
||||
// QQtMessage interface
|
||||
public:
|
||||
//把报文这条流解析出字段
|
||||
virtual void parser ( const QByteArray& l ) override {
|
||||
QByteArray _l = l;
|
||||
_l >> mSize;
|
||||
_l >> mCmd;
|
||||
_l >> mData;
|
||||
}
|
||||
//把报文字段组装成流
|
||||
virtual void packer ( QByteArray& l ) const override {
|
||||
l << mSize;
|
||||
l << mCmd;
|
||||
l << mData;
|
||||
}
|
||||
};
|
||||
|
||||
QDebug& operator << ( QDebug&, const Test10millionPeerClientMessage& msg );
|
||||
|
||||
|
||||
//业务层总是用这个协议工作,读来到的,写出去的。
|
||||
class Test10millionPeerClientProtocol : public QQtProtocol
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Test10millionPeerClientProtocol ( QObject* parent = nullptr );
|
||||
~Test10millionPeerClientProtocol();
|
||||
|
||||
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
|
||||
void recvCommand1 ( const Test10millionPeerClientMessage& msg );
|
||||
void recvCommand2 ( const Test10millionPeerClientMessage& msg );
|
||||
void sendCommand1();
|
||||
void sendCommand2();
|
||||
|
||||
signals:
|
||||
//给业务层发的信号
|
||||
void signalSendtoLogicLevelCode();
|
||||
|
||||
public slots:
|
||||
|
||||
// QQtProtocol interface
|
||||
protected:
|
||||
//报文的最小长度
|
||||
virtual quint16 minlength() override;
|
||||
//报文的最大长度
|
||||
virtual quint16 maxlength() override;
|
||||
//报文现在在流里,第一个字节,就是size,读出来,通过返回值告诉QQtProtocol
|
||||
virtual quint16 splitter ( const QByteArray& l ) override;
|
||||
|
||||
//报文现在被切开,发了进来,第二个字节是cmd,解析出来,在函数里处理处理数据,告诉业务层,拿到数据了干点什么。
|
||||
virtual bool dispatcher ( const QByteArray& m ) override;
|
||||
};
|
||||
|
||||
//业务层初始化一下这个实例,总是从这里获取协议句柄进行对外读写。
|
||||
QQtTcpClient* Test10millionPeerClientInstance ( Test10millionPeerClientProtocol*& protocol, QObject* parent = 0 );
|
||||
|
||||
#endif // TEST10MILLIONPEERCLIENTPROTOCOL_H
|
24
test/Test10millionPeerServer/AppRoot/skin/default.qss
Normal file
@ -0,0 +1,24 @@
|
||||
/*spinbox 抬起样式*/
|
||||
QTimeEdit::up-button,QDoubleSpinBox::up-button,QSpinBox::up-button {
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:right;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
QTimeEdit::down-button,QDoubleSpinBox::down-button,QSpinBox::down-button {
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:left;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
/*按钮按下样式*/
|
||||
QTimeEdit::up-button:pressed,QDoubleSpinBox::up-button:pressed,QSpinBox::up-button:pressed{
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:right;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
QTimeEdit::down-button:pressed,QDoubleSpinBox::down-button:pressed,QSpinBox::down-button:pressed,QSpinBox::down-button:pressed{
|
||||
subcontrol-position:left;
|
||||
width: 12px;
|
||||
}
|
74
test/Test10millionPeerServer/Test10millionPeerServer.pro
Normal file
@ -0,0 +1,74 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2018-10-06T08:16:10
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = Test10millionPeerServer
|
||||
TEMPLATE = app
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
SOURCES += \
|
||||
test10millionpeerserverprotocol.cpp
|
||||
HEADERS += \
|
||||
test10millionpeerserverprotocol.h
|
||||
|
||||
include($${PWD}/../../multi-link/add_base_manager.pri)
|
||||
|
||||
#-------------------------------------------------
|
||||
#用户工程配置
|
||||
#-------------------------------------------------
|
||||
add_version(1,0,0,0)
|
||||
add_deploy()
|
||||
add_deploy_config($${PWD}/AppRoot)
|
||||
add_dependent_manager(QQt)
|
||||
#add_dependent_manager(QQtHighGrade)
|
||||
system(touch main.cpp)
|
||||
|
||||
#-------------------------------------------------
|
||||
#用户工程配置
|
||||
#-------------------------------------------------
|
||||
CONFIG += console
|
||||
|
||||
equals(QSYS_PRIVATE, macOS) {
|
||||
CONFIG += app_bundle
|
||||
}
|
||||
|
||||
contains(QSYS_PRIVATE, Android|AndroidX86) {
|
||||
CONFIG += mobility
|
||||
MOBILITY =
|
||||
DISTFILES += \
|
||||
android/AndroidManifest.xml
|
||||
|
||||
ANDROID_PACKAGE_SOURCE_DIR = $${PWD}/android
|
||||
}
|
||||
|
||||
message ($${TARGET} config $${CONFIG})
|
||||
message ($${TARGET} DEFINE $${DEFINES})
|
||||
message ($${TARGET} prelink $${QMAKE_PRE_LINK})
|
||||
message ($${TARGET} postlink $${QMAKE_POST_LINK})
|
89
test/Test10millionPeerServer/android/AndroidManifest.xml
Normal file
@ -0,0 +1,89 @@
|
||||
<?xml version="1.0"?>
|
||||
<manifest package="org.qtproject.example.test10millionpeerserver" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
|
||||
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="Test10millionPeerServer" android:icon="@drawable/icon">
|
||||
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="Test10millionPeerServer" android:screenOrientation="unspecified" android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Application arguments -->
|
||||
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
|
||||
<!-- Application arguments -->
|
||||
|
||||
<meta-data android:name="android.app.lib_name" android:value="Test10millionPeerServer"/>
|
||||
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
|
||||
<meta-data android:name="android.app.repository" android:value="default"/>
|
||||
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
|
||||
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
|
||||
<!-- Deploy Qt libs as part of package -->
|
||||
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="1"/>
|
||||
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
|
||||
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
|
||||
<!-- Run with local libs -->
|
||||
<meta-data android:name="android.app.use_local_qt_libs" android:value="1"/>
|
||||
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
|
||||
<meta-data android:name="android.app.load_local_libs" android:value="plugins/platforms/android/libqtforandroid.so"/>
|
||||
<meta-data android:name="android.app.load_local_jars" android:value="jar/QtAndroid.jar:jar/QtAndroid-bundled.jar"/>
|
||||
<meta-data android:name="android.app.static_init_classes" android:value=""/>
|
||||
<!-- Messages maps -->
|
||||
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
|
||||
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
|
||||
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
|
||||
<!-- Messages maps -->
|
||||
|
||||
<!-- Splash screen -->
|
||||
<!-- meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/ -->
|
||||
<!-- meta-data android:name="android.app.splash_screen_sticky" android:value="true"/ -->
|
||||
<!-- Splash screen -->
|
||||
|
||||
<!-- Background running -->
|
||||
<!-- Warning: changing this value to true may cause unexpected crashes if the
|
||||
application still try to draw after
|
||||
"applicationStateChanged(Qt::ApplicationSuspended)"
|
||||
signal is sent! -->
|
||||
<meta-data android:name="android.app.background_running" android:value="false"/>
|
||||
<!-- Background running -->
|
||||
|
||||
<!-- auto screen scale factor -->
|
||||
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="false"/>
|
||||
<!-- auto screen scale factor -->
|
||||
|
||||
<!-- extract android style -->
|
||||
<!-- available android:values :
|
||||
* full - useful QWidget & Quick Controls 1 apps
|
||||
* minimal - useful for Quick Controls 2 apps, it is much faster than "full"
|
||||
* none - useful for apps that don't use any of the above Qt modules
|
||||
-->
|
||||
<meta-data android:name="android.app.extract_android_style" android:value="full"/>
|
||||
<!-- extract android style -->
|
||||
</activity>
|
||||
|
||||
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
|
||||
|
||||
</application>
|
||||
|
||||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16"/>
|
||||
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
|
||||
|
||||
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
|
||||
Remove the comment if you do not require these default permissions. -->
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
|
||||
Remove the comment if you do not require these default features. -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<!-- %%INSERT_PERMISSIONS -->
|
||||
<!-- %%INSERT_FEATURES -->
|
||||
<uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
|
||||
</manifest>
|
After Width: | Height: | Size: 13 KiB |
BIN
test/Test10millionPeerServer/android/res/drawable-hdpi/icon.png
Normal file
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 3.5 KiB |
BIN
test/Test10millionPeerServer/android/res/drawable-ldpi/icon.png
Normal file
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 6.0 KiB |
BIN
test/Test10millionPeerServer/android/res/drawable-mdpi/icon.png
Normal file
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 82 KiB |
11
test/Test10millionPeerServer/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QQtApplication>
|
||||
|
||||
int main ( int argc, char* argv[] )
|
||||
{
|
||||
QQtApplication a ( argc, argv );
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
14
test/Test10millionPeerServer/mainwindow.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
22
test/Test10millionPeerServer/mainwindow.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
40
test/Test10millionPeerServer/mainwindow.ui
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Test10millionPeerServer</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget"/>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
123
test/Test10millionPeerServer/test10millionpeerserverprotocol.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
#include "test10millionpeerserverprotocol.h"
|
||||
|
||||
quint32 gnum = 0;
|
||||
QMutex mutex ( QMutex::NonRecursive );
|
||||
|
||||
QDebug& operator << ( QDebug& dbg, const Test10millionPeerServerMessage& msg )
|
||||
{
|
||||
//这里打印一下,报文里面到底有什么信息,
|
||||
//一般到这里的,都是被解析好的message。
|
||||
|
||||
dbg.nospace() << "{" << hex << msg.size() << "}";
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
QQtTcpServer* Test10millionPeerServerInstance ( QQtProtocolManager*& protocolManager, QObject* parent )
|
||||
{
|
||||
static QQtProtocolManager* m0 = 0;
|
||||
if ( !m0 )
|
||||
{
|
||||
//创建Protocol管理者
|
||||
m0 = new QQtProtocolManager ( parent );
|
||||
//注册我实现的Protocol 默认1024个 如果不够用,m0有个协议句柄个数变化信号,进行动态增加。
|
||||
m0->registerProtocol<Test10millionPeerServerProtocol> ( 110000 );
|
||||
//初始化Protocol管理者完成。
|
||||
}
|
||||
protocolManager = m0;
|
||||
|
||||
static QQtTcpServer* s0 = 0;
|
||||
if ( !s0 )
|
||||
{
|
||||
//新建服务器
|
||||
s0 = new QQtTcpServer ( parent );
|
||||
//安装协议管理者
|
||||
s0->installProtocolManager ( m0 );
|
||||
//开始监听
|
||||
s0->listen ( QHostAddress::Any, 8001 );
|
||||
//服务器初始化完成。
|
||||
}
|
||||
|
||||
//等待客户端发消息过来,Protocol就处理了,去业务层看看。
|
||||
return s0;
|
||||
}
|
||||
|
||||
Test10millionPeerServerProtocol::Test10millionPeerServerProtocol ( QObject* parent )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Test10millionPeerServerProtocol::~Test10millionPeerServerProtocol()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Test10millionPeerServerProtocol::recvCommand1 ( const Test10millionPeerServerMessage& msg )
|
||||
{
|
||||
//what do you want to do?
|
||||
sendCommand1();
|
||||
}
|
||||
|
||||
void Test10millionPeerServerProtocol::recvCommand2 ( const Test10millionPeerServerMessage& msg )
|
||||
{
|
||||
//what do you want to do?
|
||||
mutex.lock();
|
||||
gnum ++;
|
||||
mutex.unlock();
|
||||
pline() << "protocol " << gnum << "complete.";
|
||||
}
|
||||
|
||||
void Test10millionPeerServerProtocol::sendCommand1()
|
||||
{
|
||||
//what do you want to do?
|
||||
Test10millionPeerServerMessage msg;
|
||||
msg.cmd() = 0x0a;
|
||||
msg.data() = 0x0aaa;
|
||||
QByteArray l;
|
||||
msg.packer ( l );
|
||||
write ( l );
|
||||
}
|
||||
|
||||
quint16 Test10millionPeerServerProtocol::minlength()
|
||||
{
|
||||
return 0x0a;
|
||||
}
|
||||
|
||||
quint16 Test10millionPeerServerProtocol::maxlength()
|
||||
{
|
||||
return 0x07FF;
|
||||
}
|
||||
|
||||
quint16 Test10millionPeerServerProtocol::splitter ( const QByteArray& l ) //stream
|
||||
{
|
||||
QByteArray s0 = l.left ( 1 );
|
||||
quint8 size = 0;
|
||||
s0 >> size;
|
||||
return size;
|
||||
}
|
||||
|
||||
bool Test10millionPeerServerProtocol::dispatcher ( const QByteArray& m ) //message
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
Test10millionPeerServerMessage qMsg;
|
||||
qMsg.parser ( m );
|
||||
pline() << qMsg;
|
||||
|
||||
switch ( qMsg.cmd() )
|
||||
{
|
||||
case 0x0a://protocol command 1
|
||||
recvCommand1 ( qMsg );
|
||||
break;
|
||||
|
||||
case 0x0b://protocol command 2
|
||||
recvCommand2 ( qMsg );
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = false;
|
||||
pline() << "receive unknown command:" << hex << qMsg.cmd();
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
#ifndef TEST10MILLIONPEERSERVERPROTOCOL_H
|
||||
#define TEST10MILLIONPEERSERVERPROTOCOL_H
|
||||
|
||||
#include <qqtmessage.h>
|
||||
#include <qqtprotocol.h>
|
||||
#include <qqtprotocolmanager.h>
|
||||
#include <qqttcpserver.h>
|
||||
|
||||
class Test10millionPeerServerMessage : public QQtMessage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Test10millionPeerServerMessage ( QObject* parent = nullptr ) {
|
||||
mSize = 0x03;//报文定长
|
||||
}
|
||||
~Test10millionPeerServerMessage() {
|
||||
|
||||
}
|
||||
|
||||
quint8& size() { return mSize; }
|
||||
const quint8& size() const { return mSize; }
|
||||
quint8& cmd() { return mCmd; }
|
||||
const quint8& cmd() const { return mCmd; }
|
||||
quint8& data() { return mData; }
|
||||
const quint8& data() const { return mData; }
|
||||
|
||||
private:
|
||||
//格式
|
||||
//|quint8 size|quint8 cmd|quint8 data|
|
||||
quint8 mSize;
|
||||
quint8 mCmd;
|
||||
quint8 mData;
|
||||
|
||||
// QQtMessage interface
|
||||
public:
|
||||
//把报文这条流解析出字段
|
||||
virtual void parser ( const QByteArray& l ) override {
|
||||
QByteArray _l = l;
|
||||
_l >> mSize;
|
||||
_l >> mCmd;
|
||||
_l >> mData;
|
||||
}
|
||||
//把报文字段组装成流
|
||||
virtual void packer ( QByteArray& l ) const override {
|
||||
l << mSize;
|
||||
l << mCmd;
|
||||
l << mData;
|
||||
}
|
||||
};
|
||||
|
||||
QDebug& operator << ( QDebug& dbg, const Test10millionPeerServerMessage& msg );
|
||||
|
||||
//业务层总是用这个协议工作,读来到的,写出去的。
|
||||
class Test10millionPeerServerProtocol : public QQtProtocol
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Test10millionPeerServerProtocol ( QObject* parent = nullptr );
|
||||
~Test10millionPeerServerProtocol();
|
||||
|
||||
//收到外部发来的很多命令,处理一下告诉业务层干点什么。
|
||||
void recvCommand1 ( const Test10millionPeerServerMessage& msg );
|
||||
void recvCommand2 ( const Test10millionPeerServerMessage& msg );
|
||||
|
||||
void sendCommand1();
|
||||
|
||||
signals:
|
||||
//给业务层发的信号
|
||||
void signalSendtoLogicLevelCode();
|
||||
|
||||
public slots:
|
||||
|
||||
// QQtProtocol interface
|
||||
protected:
|
||||
//报文的最小长度
|
||||
virtual quint16 minlength() override;
|
||||
//报文的最大长度
|
||||
virtual quint16 maxlength() override;
|
||||
//报文现在在流里,第一个字节,就是size,读出来,通过返回值告诉QQtProtocol
|
||||
virtual quint16 splitter ( const QByteArray& l ) override;
|
||||
|
||||
//报文现在被切开,发了进来,第二个字节是cmd,解析出来,在函数里处理处理数据,告诉业务层,拿到数据了干点什么。
|
||||
virtual bool dispatcher ( const QByteArray& m ) override;
|
||||
};
|
||||
|
||||
//用户使用这里的ProtocolManager进行必要的和客户端的通信。一般在Test10millionPeerServerProtocol里面解决。
|
||||
QQtTcpServer* Test10millionPeerServerInstance ( QQtProtocolManager*& protocolManager, QObject* parent );
|
||||
|
||||
#endif // TEST10MILLIONPEERSERVERPROTOCOL_H
|