PDA

View Full Version : QTcpServer and QTcpClient



GBunge
24th December 2013, 14:47
Hi,
for an InterProcessCommunication between a OSX und Linux
I developed server- and clientprocesses on the Mac with QtCreator.

The client sends a question to the server. The server solves the problem
an sends the answer back to the client.
All works fine!

But when I starts the two processes outside the QtCreator, nothing works!
The server and client works correct ( checked with status-messages ),
but data are'nt swap.

As a test, i try it with QLocalServer and QLocalSocket. In this case all works fine.
I can start the applications outside QtCreator and the data will be changed.
But in the LAN ( OSX and Linux ) this could'nt work.

Thanks for solutions.

My english is'nt perfect, so I hope you understand what I wrote!
Happy Christmas GBunge

anda_skoa
24th December 2013, 16:32
There is really not enough information to provide any meaningful help :(

Can you verify that the QTcpServer's listen() works? I.e. does it return "true"?
Are you testing with both on the same machine?

Cheers,
_

GBunge
25th December 2013, 08:30
Hi,
first, both tests on the same machine! (Mac)

Start inside QtCreator all works!

Start outside:
The connection is established.
The server listen returns 'true'.
If I start the client without running the server, a statusmessage pops up "server not online".

Make it sense, when I post the code of the two applications?
And how can I do it?

GBunge

anda_skoa
25th December 2013, 10:51
You can attach a ZIP file containing the project.

Cheers,
_

GBunge
26th December 2013, 10:24
Hi anda_skoa,

the problem is fixed!
In the memberfunction 'void IPCServer::readData()'


void IPCServer::readData()
{ QDataStream in( client );
// Byte-Anzahl auslesen ++++++++++++++++++++++++++
if( anzahl == 0)
{ if( client->bytesAvailable() < (int)sizeof(quint16)) return;
in >> anzahl;
}
if( client->bytesAvailable() < anzahl) return;
// Socket auslesen +++++++++++++++++++++++++++++++
in >> data;
// Antwort berechnen +++++++++++++++++++++++++++++
compute( data );
// Antwort senden ++++++++++++++++++++++++++++++++
sendData();
anzahl = 0;
}

the Classvariable 'anzahl' are not 0.
Therefor the metode couldn't work.
I forgot to initialising this variable in the constructor.

But the mysterium:
inside QtCreator there is no consequence,
outside QtCreator the consequence is 'no datatransfer',
I don't understand this! But it runs!

Thanks for your time!
GBunge

wysota
26th December 2013, 13:33
If you get different behavior in and outside of Creator then it means you are running two different binaries.

anda_skoa
26th December 2013, 14:13
If anzahl was not 0 because it was not properly initialized then it might have worked in creator just out of pure luck, i.e. the memory incidentally being 0 in that case.

Cheers,
_