This is an automated email from the git hooks/post-receive script. x2go pushed a change to branch feature/udp-support in repository x2gokdriveclient. from d23a146 Send only frames over UDP new 371b471 Establishing UDP connection. The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Summary of changes: client.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++---------------- client.h | 7 +++++ 2 files changed, 82 insertions(+), 27 deletions(-) -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2gokdriveclient.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch feature/udp-support in repository x2gokdriveclient. commit 371b471c8a02cbc4759c53531904b7b19f3d5472 Author: Oleksandr Shneyder <o.shneyder@phoca-gmbh.de> Date: Tue Dec 20 15:00:49 2022 -0600 Establishing UDP connection. --- client.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++---------------- client.h | 7 +++++ 2 files changed, 82 insertions(+), 27 deletions(-) diff --git a/client.cpp b/client.cpp index fa7f745..c42ddc9 100644 --- a/client.cpp +++ b/client.cpp @@ -233,17 +233,8 @@ Client::Client() connect(clientSocket, SIGNAL(readyRead()), this, SLOT(dataArrived()) ); -#warning take code for udp socket here - /* - { - clientSocket=new QUdpSocket(this); - connect((QUdpSocket*)clientSocket, SIGNAL(connected()), this, SLOT(socketConnected())); - connect((QUdpSocket*)clientSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); - connect((QUdpSocket*)clientSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError))); - connect((QUdpSocket*)clientSocket, SIGNAL(readyRead()), this, SLOT(dataArrived()) ); - }*/ - - + udpSocket=new QUdpSocket(this); + connect(udpSocket, SIGNAL(readyRead()), this, SLOT(udpDataArrived())); #ifndef Q_OS_LINUX connect(QGuiApplication::clipboard(), SIGNAL(changed(QClipboard::Mode)), this, SLOT(slotSelectionChanged(QClipboard::Mode))); @@ -629,6 +620,12 @@ void Client::parseOptions() KDRStdErr()<<"Running in debug mode"; continue; } + if(args[i]=="--udp-frames") + { + udpFrames=true; + udpHost=args[++i]; + continue; + } if(args[i]=="--connect") { host=args[++i]; @@ -771,14 +768,8 @@ void Client::parseOptions() void Client::connectToServer() { // setWindowTitle("X2GO SESSION"); - KDRStdErr(false)<<"Connecting to remote host "<<host<<":"<<port<<" over TCP"<<KDR_ENDL; clientSocket->connectToHost(host, port); -#warning use this to open udp connection -/* { - KDRStdErr(false)<<"Connecting to remote host "<<host<<":"<<port<<" over UDP"<<KDR_ENDL; - ((QUdpSocket*)clientSocket)->connectToHost(host, port); - }*/ } @@ -787,10 +778,13 @@ QPixmap Client::getPixmapFromCache(uint32_t crc) if(!frameCache.contains(crc)) { KDRStdErr()<<"GETPIXMAP: frame "<<KDR_HEX<<crc<<" not found in cache"<<KDR_ENDL; -/* if(serverVersion<5) - exitOnError(tr("Frame not found in cache")); - else - requestCacheRebuild();*/ + if(serverVersion<5) + return QPixmap(); + if(serverVersion<8) + { + requestCacheRebuild(); + return QPixmap(); + } requestFrame(crc); return QPixmap(); } @@ -1071,6 +1065,14 @@ void Client::getServerversion() checkSrvAliveTimer->start(SERVERALIVETIMEOUT*1000); } initGeometry(); + if(serverVersion>=8) + { + QTimer* t=new QTimer(this); + connect(t, SIGNAL(timeout()), this, SLOT(slotSynchronize())); + t->start(5000); + if(udpFrames) + requestUdpFrames(); + } } void Client::getClientSelection() @@ -1733,9 +1735,21 @@ void Client::readDataHeader() slotDisconnect(); break; } + case UDPOPEN: + { + openUdpConnection(); + break; + } + case UDPFAILED: + { + KDRStdErr()<<"Server rejected UDP connection, trying one more time..."; + requestUdpFrames(); + break; + } default: { KDRStdErr()<<"Unsupported header type: "<<data_type; + freeMessageBuffer(); exitOnError(tr("Unsupported header type")); break; } @@ -2013,12 +2027,6 @@ void Client::socketConnected() sendClientVersion(); QTimer::singleShot(2000, this, SLOT(checkServerVersion())); //if connected over tcp, sending synchronization packages. In other case, just sending KEEPALIVE packets - if( serverVersion >=8) - { - QTimer* t=new QTimer(this); - connect(t, SIGNAL(timeout()), this, SLOT(slotSynchronize())); - t->start(5000); - } } void Client::checkServerVersion() @@ -2634,3 +2642,43 @@ void Client::updateServerAlive() if(checkSrvAliveTimer) checkSrvAliveTimer->start(SERVERALIVETIMEOUT*1000); } + +void Client::requestUdpFrames() +{ + if(udpConnectionAttempts>=3) + { + KDRStdErr()<<"Failed to establish UDP connection, continue over TCP"<<KDR_ENDL; + return; + } + char evmsg[EVLENGTH]{}; + uint32_t etype; + etype=OPENUDP; + memcpy(evmsg,(char*)&etype,4); + KDRStdErr()<<"Requesting UDP connection, attempt number "<<++udpConnectionAttempts<<KDR_ENDL; + sendEvent(evmsg); +} + +void Client::openUdpConnection() +{ + int32_t udp_port=*((uint16_t*)messageBuffer+2); + int32_t tmp_cookie[8]; + memcpy(tmp_cookie, messageBuffer+8,8*4); + KDRStdErr()<<"Server is listening on UDP port: "<<udp_port<<KDR_ENDL; + KDRStdErr(false)<<"Connecting to remote host "<<udpHost<<":"<<udp_port<<" over UDP"<<KDR_ENDL; + udpSocket->connectToHost(udpHost, udp_port); + if(!udpSocket->waitForConnected(3000)) + { + KDRStdErr(false)<<"Warning, can't establish UDP connection"<<KDR_ENDL; + } + else + { + KDRStdErr(false)<<"UDP connection established"<<KDR_ENDL; + udpSocket->write((char*)tmp_cookie,8*4); + } + +// for(int i=0;i<8;++i) +// { +// KDRStdErr()<<"Cookie "<<i<<" - "<<tmp_cookie[i]<<KDR_ENDL; +// } + +} diff --git a/client.h b/client.h index 33ee7d1..6ff2ef4 100644 --- a/client.h +++ b/client.h @@ -212,6 +212,7 @@ class QLabel; class ScreenIdentifier; class ExtWin; class QTcpSocket; +class QUdpSocket; class Client : public QMainWindow { @@ -305,6 +306,8 @@ private: void getWinUpdate(); void getWinUpdateBuffer(); void renderFrame(); + void requestUdpFrames(); + void openUdpConnection(); void freeMessageBuffer(); void setCursor(); void sendGeometryEvent(); @@ -331,6 +334,7 @@ private: int width=800; int height=600; QString host="localhost"; + QString udpHost="localhost"; int port=15000; @@ -342,6 +346,8 @@ private: int dispNumber=1; bool serverExtSelection=false; bool rootless=false; + bool udpFrames=false; + int udpConnectionAttempts=0; time_t lastServerPacketTime=0; QString cookie; @@ -370,6 +376,7 @@ private: Qt::WindowFlags savedFlags; QTcpSocket* clientSocket=0l; + QUdpSocket* udpSocket=0l; int bytesLeftToRead=0; int bytesReady=0; char* messageBuffer=0l; -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2gokdriveclient.git