Hello!
I am developing the VNC-client for Sailfish OS using Qt and faced with the following problem.
After calling the SendExtDesktopSize() function after retrieving first frames the server connection fails and I have the messages "read (104: Connection reset by peer)" and "VNC connection closed" in logs.
Part of my code.
Code inside the client-class constructor:
- Initializes and sets up the
rfbClient instance,
- Sets up signals of timer to run retrieving the rfb-messages every 10 millis.
// init rfbClient instance
m_rfbClient = rfbGetClient(8, 3, 4);
m_rfbClient->GetCredential = GetCredential;
m_rfbClient->GetPassword = GetPassword;
m_rfbClient->MallocFrameBuffer = MallocFrameBuffer;
m_rfbClient->GotFrameBufferUpdate = GotFrameBufferUpdate;
m_rfbClient->frameBuffer = nullptr;
m_rfbClient->canHandleNewFBSize = true;
// set up signals and slots of timer to retrieve the rfb-messages
m_updateTimer.setInterval(10);
connect(&m_updateTimer, &QTimer::timeout, this, &VNCClient::runWaitingRfbMessage);
connect(this, SIGNAL(connected(QSize)), &m_updateTimer, SLOT(start()));
connect(this, &VNCClient::disconnected, &m_updateTimer, &QTimer::stop);
Method to perform a connection to the VNC-server:
void VNCClient::connectToHost(const QString &hostName, const QString &port, const QString &username, const QString &password)
{
m_userName = username;
m_password = password;
try {
if (!ConnectToRFBServer(m_rfbClient, hostName.toUtf8(), port.toInt()))
throw QStringLiteral("Unable to connect to VNC server %1:%2").arg(hostName, port);
if (!InitialiseRFBConnection(m_rfbClient))
throw QStringLiteral("Connection initialization failed");
m_rfbClient->appData.encodingsString = "ultra";
m_rfbClient->appData.qualityLevel = 5;
m_rfbClient->appData.compressLevel = 9;
if (!SetFormatAndEncodings(m_rfbClient))
throw QStringLiteral("Set format and encoding failed");
if (m_rfbClient->width == 0 && m_rfbClient->height == 0) {
m_rfbClient->width = m_rfbClient->si.framebufferWidth;
m_rfbClient->height = m_rfbClient->si.framebufferHeight;
m_rfbClient->screen.width = m_rfbClient->si.framebufferWidth;
m_rfbClient->screen.height = m_rfbClient->si.framebufferHeight;
}
MallocFrameBuffer(m_rfbClient);
requestUpdate();
emit connected(QSize(m_rfbClient->width, m_rfbClient->height));
} catch (const QString &error) {
emit errorOccured(error);
}
}
Method to disconnect from the server:
void VNCClient::disconnectFromHost()
{
if (m_rfbClient->sock) {
close(m_rfbClient->sock);
m_rfbClient->sock = 0;
}
if (m_rfbClient->frameBuffer) {
free(m_rfbClient->frameBuffer);
m_rfbClient->frameBuffer = nullptr;
}
if (m_lastErrorMessage.isEmpty()) {
emit disconnected("", "");
} else {
qWarning() << "VNC Error" << m_lastErrorMessage;
emit disconnected(m_lastErrorMessage, QStringLiteral("vnc"));
}
}
Method to retrieve the rfb-messages. It calls requestUpdate() to send a message to update framebuffer in a separate thread via QTimer.
void VNCClient::runWaitingRfbMessage()
{
if (WaitForMessage(m_rfbClient, 0)) {
if (HandleRFBServerMessage(m_rfbClient)) {
QTimer::singleShot(25, Qt::CoarseTimer, this, &VNCClient::requestUpdate);
}
}
}
Method to send a message to update the framebuffer.
void VNCClient::requestUpdate()
{
m_rfbClient->updateRect.x = 0;
m_rfbClient->updateRect.y = 0;
m_rfbClient->updateRect.w = m_rfbClient->width;
m_rfbClient->updateRect.h = m_rfbClient->height;
SendIncrementalFramebufferUpdateRequest(m_rfbClient);
}
Method initializes the framebuffer.
rfbBool VNCClient::MallocFrameBuffer(rfbClient *rfbClient)
{
if (rfbClient->frameBuffer)
free(rfbClient->frameBuffer);
rfbClient->frameBuffer = (uint8_t *)malloc(rfbClient->width * rfbClient->height * vncBytesPerPixel);
return TRUE;
}
Also for testing I call SendExtDesktopSize(m_rfbClient, m_width, m_height); through clicking a button inside an app when the server gives me a picture and the picture is displayed. And when the call is finished I got an error that described above.
For running my client-app I use INOI R7.
The problem is reproduced when it's used Vine VNC Server for macOS and TightVNC for Windows as servers.
The problem is not reproduced when it's used UltraVNC for Windows as a server.
Can you please tell me what I'm doing wrong?
Hello!
I am developing the VNC-client for Sailfish OS using Qt and faced with the following problem.
After calling the
SendExtDesktopSize()function after retrieving first frames the server connection fails and I have the messages "read (104: Connection reset by peer)" and "VNC connection closed" in logs.Part of my code.
Code inside the client-class constructor:
rfbClientinstance,Method to perform a connection to the VNC-server:
Method to disconnect from the server:
Method to retrieve the rfb-messages. It calls
requestUpdate()to send a message to update framebuffer in a separate thread via QTimer.Method to send a message to update the framebuffer.
Method initializes the framebuffer.
Also for testing I call
SendExtDesktopSize(m_rfbClient, m_width, m_height);through clicking a button inside an app when the server gives me a picture and the picture is displayed. And when the call is finished I got an error that described above.For running my client-app I use INOI R7.
The problem is reproduced when it's used Vine VNC Server for macOS and TightVNC for Windows as servers.
The problem is not reproduced when it's used UltraVNC for Windows as a server.
Can you please tell me what I'm doing wrong?