Can QTCPSocket be converted to QNetworkRequest?
-
Hello guys,
I am learning web server languages myself. I am trying golang and node.js, and planned to write a simple blog system to get familiar with these languages. But after trying some node.js, I then thought about writing the blog with QT and c++.
What I want to learn is why people now favor Go and node.js over C++/QT for implementing web apps? Can I write a web app framework with QT which is similar to express.js, or others that are available to python and ruby?
I found an example QT http server, http://doc.qt.nokia.com/solutions/4/qtservice/qtservice-example-server.html
however, this example parses the http header with Regular Expressions,
my question is, if it is possible to create a QNetworkRequest directly from a QTcpSocket, such that I don't need to use RegExp to parse the http header?
It seems to me that QNetworkRequest is mainly used by a client, not a server, to send a http request, not to receive one.
Is this true?An additional question,
node.js describes itself as event io for javascript. it uses a single thread, but non-blocking functions to handle io. So what is the best practice of writing an efficient web server? using multiple threads or single thread with non-blocking io? Can these two be mixed?
What does node.js mean by "io"? accessing database? if my web app doesn't access database or files, but only access from the memory, will node.js still be efficient compared to others?
-
[quote author="billconan" date="1311191151"]
What I want to learn is why people now favor Go and node.js over C++/QT for implementing web apps? Can I write a web app framework with QT which is similar to express.js, or others that are available to python and ruby?
[/quote]Surely you CAN write a webapp framework with Qt, but I don't think it's one of the scopes of the framework :)
[quote]
my question is, if it is possible to create a QNetworkRequest directly from a QTcpSocket, such that I don't need to use RegExp to parse the http header?It seems to me that QNetworkRequest is mainly used by a client, not a server, to send a http request, not to receive one.
Is this true?
[/quote]Correct. QNR represents an outgoing request from a client, and Qt doesn't offer a way to parse client headers to build a QNR back. You have to implement such a parser yourself (f.i. by using a library like http://github.com/ry/http-parser )
[quote]
node.js describes itself as event io for javascript. it uses a single thread, but non-blocking functions to handle io. So what is the best practice of writing an efficient web server? using multiple threads or single thread with non-blocking io? Can these two be mixed?
[/quote]
Yes. You can have multiple threads with non blocking io. It just makes the design very complicated, and possibly it's not worth the effort (f.i. it could be much easier to scale just by putting a load balancer in front of two instances). And notice that Qt does NOT support async I/O for files.[quote]
What does node.js mean by "io"? accessing database? if my web app doesn't access database or files, but only access from the memory, will node.js still be efficient compared to others?[/quote]Don't know the answer, but this is quite offtopic.
-
You should google a bit on "Qt webserver". There is plenty of code to be found that goes into the direction you're interested in, but as peppe said: QNAM and friends are geared towards the client end of business, not the server end.