mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-07-18 23:11:29 +00:00
server 正向代理功能完成
This commit is contained in:
parent
eef4da59c9
commit
77d6c930d4
4 changed files with 33 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.6.2, 2018-10-11T19:35:50. -->
|
<!-- Written by QtCreator 4.6.2, 2018-10-11T22:14:16. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
@ -292,7 +292,7 @@
|
||||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">QtScrcpy.pro</value>
|
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">QtScrcpy.pro</value>
|
||||||
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
|
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
|
||||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
|
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
|
||||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default"></value>
|
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">G:/mygitcode/QtScrcpy/build-QtScrcpy-Desktop_Qt_5_9_6_MSVC2015_32bit-Debug</value>
|
||||||
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
|
|
@ -9,6 +9,11 @@ Dialog::Dialog(QWidget *parent) :
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
server = new Server();
|
server = new Server();
|
||||||
|
connect(server, &Server::serverStartResult, this, [this](bool success){
|
||||||
|
if (success) {
|
||||||
|
server->connectTo();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog::~Dialog()
|
Dialog::~Dialog()
|
||||||
|
@ -28,6 +33,7 @@ void Dialog::on_adbProcess_clicked()
|
||||||
void Dialog::on_startServerBtn_clicked()
|
void Dialog::on_startServerBtn_clicked()
|
||||||
{
|
{
|
||||||
server->start("P7C0218510000537", 27183, 0, 8000000, "");
|
server->start("P7C0218510000537", 27183, 0, 8000000, "");
|
||||||
|
//server->start("P7CDU17C23010875", 27183, 0, 8000000, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::on_stopServerBtn_clicked()
|
void Dialog::on_stopServerBtn_clicked()
|
||||||
|
|
|
@ -149,20 +149,31 @@ bool Server::start(const QString& serial, quint16 localPort, quint16 maxSize, qu
|
||||||
return startServerByStep();
|
return startServerByStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::connectTo()
|
bool Server::connectTo()
|
||||||
{
|
{
|
||||||
|
if (SSS_RUNNING != m_serverStartStep) {
|
||||||
|
qWarning("server not run");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (m_tunnelForward) {
|
if (m_tunnelForward) {
|
||||||
m_deviceSocket = new QTcpSocket(this);
|
m_deviceSocket = new QTcpSocket(this);
|
||||||
connect(m_deviceSocket, &QTcpSocket::disconnected, m_deviceSocket, &QTcpSocket::deleteLater);
|
connect(m_deviceSocket, &QTcpSocket::disconnected, m_deviceSocket, &QTcpSocket::deleteLater);
|
||||||
//connect(m_deviceSocket, &QTcpSocket::error, m_deviceSocket, &QTcpSocket::deleteLater);
|
//connect(m_deviceSocket, &QTcpSocket::error, m_deviceSocket, &QTcpSocket::deleteLater);
|
||||||
connect(m_deviceSocket, &QTcpSocket::readyRead, this, [this](){
|
connect(m_deviceSocket, &QTcpSocket::readyRead, this, [this](){
|
||||||
qDebug() << "ready read";
|
static quint64 count = 0;
|
||||||
m_deviceSocket->readAll();
|
qDebug() << count << "ready read";
|
||||||
|
count++;
|
||||||
|
});
|
||||||
|
|
||||||
|
// wait for devices server start
|
||||||
|
QTimer::singleShot(1000, this, [this](){
|
||||||
|
if (m_deviceSocket) {
|
||||||
|
m_deviceSocket->connectToHost(QHostAddress::LocalHost, m_localPort);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
m_deviceSocket->connectToHost(QHostAddress::LocalHost, m_localPort);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTimer::singleShot(300, this, [this](){
|
QTimer::singleShot(1200, this, [this](){
|
||||||
if (!m_deviceSocket) {
|
if (!m_deviceSocket) {
|
||||||
emit connectToResult(false);
|
emit connectToResult(false);
|
||||||
return;
|
return;
|
||||||
|
@ -204,9 +215,11 @@ void Server::connectTo()
|
||||||
} else {
|
} else {
|
||||||
disableTunnelReverse();
|
disableTunnelReverse();
|
||||||
}
|
}
|
||||||
|
m_tunnelEnabled = false;
|
||||||
}
|
}
|
||||||
emit connectToResult(success);
|
emit connectToResult(success);
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::stop()
|
void Server::stop()
|
||||||
|
@ -219,9 +232,12 @@ void Server::stop()
|
||||||
} else {
|
} else {
|
||||||
disableTunnelReverse();
|
disableTunnelReverse();
|
||||||
}
|
}
|
||||||
|
m_tunnelForward = false;
|
||||||
|
m_tunnelEnabled = false;
|
||||||
}
|
}
|
||||||
if (m_serverCopiedToDevice) {
|
if (m_serverCopiedToDevice) {
|
||||||
removeServer();
|
removeServer();
|
||||||
|
m_serverCopiedToDevice = false;
|
||||||
}
|
}
|
||||||
m_serverSocket.close();
|
m_serverSocket.close();
|
||||||
if (m_deviceSocket) {
|
if (m_deviceSocket) {
|
||||||
|
@ -325,7 +341,7 @@ void Server::onWorkProcessResult(AdbProcess::ADB_EXEC_RESULT processResult)
|
||||||
if (sender() == &m_serverProcess) {
|
if (sender() == &m_serverProcess) {
|
||||||
if (SSS_EXECUTE_SERVER == m_serverStartStep) {
|
if (SSS_EXECUTE_SERVER == m_serverStartStep) {
|
||||||
if (AdbProcess::AER_SUCCESS_START == processResult) {
|
if (AdbProcess::AER_SUCCESS_START == processResult) {
|
||||||
m_serverStartStep = SSS_NULL;
|
m_serverStartStep = SSS_RUNNING;
|
||||||
m_tunnelEnabled = true;
|
m_tunnelEnabled = true;
|
||||||
emit serverStartResult(true);
|
emit serverStartResult(true);
|
||||||
} else if (AdbProcess::AER_ERROR_START == processResult){
|
} else if (AdbProcess::AER_ERROR_START == processResult){
|
||||||
|
|
|
@ -18,12 +18,13 @@ class Server : public QObject
|
||||||
SSS_ENABLE_TUNNEL_REVERSE,
|
SSS_ENABLE_TUNNEL_REVERSE,
|
||||||
SSS_ENABLE_TUNNEL_FORWARD,
|
SSS_ENABLE_TUNNEL_FORWARD,
|
||||||
SSS_EXECUTE_SERVER,
|
SSS_EXECUTE_SERVER,
|
||||||
|
SSS_RUNNING,
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
explicit Server(QObject *parent = nullptr);
|
explicit Server(QObject *parent = nullptr);
|
||||||
|
|
||||||
bool start(const QString& serial, quint16 localPort, quint16 maxSize, quint32 bitRate, const QString& crop);
|
bool start(const QString& serial, quint16 localPort, quint16 maxSize, quint32 bitRate, const QString& crop);
|
||||||
void connectTo();
|
bool connectTo();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -44,6 +45,7 @@ private:
|
||||||
bool execute();
|
bool execute();
|
||||||
bool startServerByStep();
|
bool startServerByStep();
|
||||||
|
|
||||||
|
private:
|
||||||
QString m_serverPath = "";
|
QString m_serverPath = "";
|
||||||
AdbProcess m_workProcess;
|
AdbProcess m_workProcess;
|
||||||
QString m_serial = "";
|
QString m_serial = "";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue