mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-07-23 17:31:30 +00:00
server功能完善
This commit is contained in:
parent
77d6c930d4
commit
1a28828c13
2 changed files with 30 additions and 13 deletions
|
@ -16,13 +16,14 @@ Server::Server(QObject *parent) : QObject(parent)
|
||||||
m_deviceSocket = m_serverSocket.nextPendingConnection();
|
m_deviceSocket = m_serverSocket.nextPendingConnection();
|
||||||
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](){
|
|
||||||
static quint64 count = 0;
|
// connect(m_deviceSocket, &QTcpSocket::readyRead, this, [this](){
|
||||||
qDebug() << count << "ready read";
|
// static quint64 count = 0;
|
||||||
count++;
|
// qDebug() << count << "ready read";
|
||||||
QByteArray ar = m_deviceSocket->readAll();
|
// count++;
|
||||||
//m_deviceSocket->write(ar);
|
// QByteArray ar = m_deviceSocket->readAll();
|
||||||
});
|
// //m_deviceSocket->write(ar);
|
||||||
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -159,11 +160,11 @@ bool Server::connectTo()
|
||||||
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](){
|
||||||
static quint64 count = 0;
|
// static quint64 count = 0;
|
||||||
qDebug() << count << "ready read";
|
// qDebug() << count << "ready read";
|
||||||
count++;
|
// count++;
|
||||||
});
|
// });
|
||||||
|
|
||||||
// wait for devices server start
|
// wait for devices server start
|
||||||
QTimer::singleShot(1000, this, [this](){
|
QTimer::singleShot(1000, this, [this](){
|
||||||
|
@ -222,6 +223,21 @@ bool Server::connectTo()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint32 Server::recvData(quint8* buf, qint32 bufSize)
|
||||||
|
{
|
||||||
|
if (!buf) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (m_deviceSocket) {
|
||||||
|
while (m_deviceSocket->bytesAvailable() < bufSize) {
|
||||||
|
if (m_deviceSocket->waitForReadyRead()) {
|
||||||
|
return m_deviceSocket->read((char*)buf, bufSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Server::stop()
|
void Server::stop()
|
||||||
{
|
{
|
||||||
// ignore failure
|
// ignore failure
|
||||||
|
|
|
@ -23,8 +23,9 @@ class Server : public QObject
|
||||||
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);
|
||||||
bool connectTo();
|
bool connectTo();
|
||||||
|
qint32 recvData(quint8* buf, qint32 bufSize);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue