Problem with sockets
-
Hi,
I have to communicate with a server using sockets and fetch some data that are URL-encoded. Some of the data I must read is a URL value. It can assume two forms:
- A simple URL, like http://www.google.com, that comes as "http://www.google.com"
- A URL containing another URL for redirection, like http://www.someurl.com/foo?bar=http://www.redirecttohere.com, that comes encoded as http://www.someurl.com/foo?bar=http%3A%2F%2Fwww.redirecttohere.com
In the second case (and only in it!), when I fetch the data using QTcpSockets, the data seems to be corrupted. When QTcpSocket reads the data that I receive as http://www.someurl.com/foo?bar=http%3A%2F%2Fwww.redirecttohere.com when I test the protocol using a telnet client, it puts some characters in some places of the string and breaks the URL encoding.
Using a Telnet connection I can get the right values. When I use QTcpSocket to fetch the data it gets corrupted with some non-printing characters that break the correct decoding.
My readyData() signal is processed with this slot:
@void ConnectionHandler::readReply() {
QByteArray serverReplyArray;
while (socket->canReadLine()) {
serverReplyArray.append(socket->readLine().trimmed());
}if (!serverReplyArray.isEmpty()) { emit serverReply(serverReplyArray); }
}@
Any tip?
-
I had similar task but my data was not only string but also binary so I wrote code for transmitting data using QTcpSocket::write() and QTcpSocket::readAll(). The data itself was QByteArray with some other types stored in it with QDataStream.
Since this way seems redundant for your task could you provide minimal working example?