Data exchange between PHP and the server application in C++ with Qt4?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
5 views
You need PHP on the server to transfer application data via SSL, wait for response data and display them on the screen.


Wrote this code in PHP:
<?phperror_reporting(E_ALL);$fp = fsockopen("ssl://localhost", 6000);$send = "hello";fputs($fp, $send);$html = fread($fp, 1000000);fclose($fp);echo "<pre>".$html."
"; ?>


And the function of receiving messages in QT4
void CConnThread::slotReadyRead() { //Create the data flow. QDataStream in(sslSocket); in.the setversion(QDataStream::Qt_4_4); //If came the first part of the sent client information. if(blockSize == 0) { cout << "data transfer from client" << endl; //If the first part is smaller than the count of the information that determines the size of the entire message... if(sslSocket->bytesAvailable() < (int)sizeof(qint64)) return; //Get the size sent by the client message. in >> blockSize; } //If the next part together less than a certain client number... if(sslSocket->bytesAvailable() < blockSize) return; //Reset the size parameter sent by the client message. blockSize = 0; //Get the string network message. QString message; in >> message; //Next, we create...;) cout << message.toAscii().data() << endl; this->sendMessage("received!"); } void CConnThread::sendMessage(QString message) { QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out.the setversion(QDataStream::Qt_4_4); out << (qint64)0; out << message; out.device()->seek(0); out << (qint64)(block.size() - sizeof(qint64)); sslSocket->write(block); }



But here's the problem — the data arrive (as evidenced by the output line of the data transfer from the client), but not displayed. The very same PHP script hangs after sending (waiting for a response, but not receiving it). What did I do wrong?
by | 5 views

6 Answers

0 like 0 dislike
Not the fact that the data arrives, because if(blockSize == 0) says that if the variable is zero, then it will take place, so uterati that the data came from for these reasons is wrong. You need to use debugging, so I can't tell you. In the variable also can store "garbage", you need to use malloc to zero out memory. It is concerned with C++
\r
But in the PHP code where it checks whether the opened socket is there continuity?
Maybe the port to which You connect is closed. and You connect on the 6000 port, and the like 3665 for TCP.
\r
I do in programming is not strong, but maybe it somehow helps.
by
0 like 0 dislike
If all runs under Linux you can use strace to run the script and qt app and see what system calls are.
by
0 like 0 dislike
I suspect that it is necessary to write to the socket data in the same format in which QT serializes strings.
There should at least be present or a sign of the end of the string or its length.
\r
Then no reason to read the message size from the socket, if it is there?
Anyway, fputs does not write to handle anything except what he was given.
by
0 like 0 dislike
Of course the same. Because of this
\r
QString message; in >> message;
\r
it is necessary first to write to socket the correct length of the string.
by
0 like 0 dislike
Same thing:
\r
\r
\r<?php\rinclude_once('doc.write.php');\r\rerror_reporting(E_ALL);\r\r$fp = fsockopen("ssl://localhost", 6000);\r\r$send = doc_write_create();\rdoc_write_ui8($send, 6);\rdoc_write_string($send, "hello");\r\rfputs($fp, doc_write_content($send));\r$html = fread($fp, 1000000);\rfclose($fp);\r\recho "<pre>".$html."
"; ?>
\r
On the server:
INFORMATION: tcp server is listen on address and port 6000 0x9afe312
INFORMATION: incoming of new connection 8
INFORMATION: the client was connected
connection encrypted
data transfer from client
here it should output hello.
by
0 like 0 dislike
Turns out I mixed up little endian and big endian. Now the output looks like this:
\r
INFORMATION: tcp server is listen on address and port 6000 0x8e15312
INFORMATION: incoming of new connection 8
INFORMATION: the client was connected
connection encrypted
data transfer from client
\r
INFORMATION: the client was disconnected
INFORMATION: thread client was destroyed
\r
But somehow, the string on the server is empty (although the size is read correct). And in PHP script not output the answer.
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
5 answers
0 like 0 dislike
1 answer
asked Mar 22, 2019 by Robotex
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
28,140 users