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