Re: QtcpSocket read behavior
up, other tests, same problem :(
Re: QtcpSocket read behavior
Your code works fine on my Debian box. I use netcat to connect (nc localhost 5500) and using your input get the following on the console:
Code:
wait read...
10--testline1
wait read...
15--testline222222
wait read...
1--
wait read...
13--lastwasempty
wait read...
Try putting in a qDebug() statement to see what you're actually receiving:
Code:
qDebug() << a.toHex();
if (a.endsWith("\r\n"))
Re: QtcpSocket read behavior
Note that you may not receive data in the same size as what was sent. So if you sent "hello\r\n" for example, you might receive "hello" in one read and "\r\n" in another.
Therefore put your debugging before you strip such a sequence and you may find this is happening.
Re: QtcpSocket read behavior
Quote:
Try putting in a qDebug() statement to see what you're actually receiving:
line added.
Maybe is exactly this the problem (or maybe it's a putty problem) because i've done 2 tests:
TEST 1:
1) server on a ubuntu based vps piloted via ssh(putty)
2) raw connection with putty to server on port 5500
the lines sended are:
and the server print(che std::cout line was deleted):
Code:
wait read...
"6c696e65"
wait read...
"0d0a"
TEST 2:
with this test:
1) same as last test
2) another ssh session to vps, and now the connection is done simply by "telnet localhost 5500"
the line sent was the same as last test ("line")
but the result was:
Code:
wait read...
"6c696e650d0a"
maybe can be putty that do something strange before send the data?
Quote:
Note that you may not receive data in the same size as what was sent. So if you sent "hello\r\n" for example, you might receive "hello" in one read and "\r\n" in another.
Therefore put your debugging before you strip such a sequence and you may find this is happening.
ok..but if it's a normal behavior, how cqan i recognize the differences between a blank line sended (which receive only "\r\n") and a non-blank line which receive the data in one read and the \r\n in another?
Re: QtcpSocket read behavior
You could change your logic a bit:
Code:
while(true){
so->waitForReadyRead(5000000);
a.append(so->read(1000));
if(a.endsWith("\n")) {
if(a.endsWith("\r\n")) a.chop(2); else a.chop(1);
qDebug() << a ;
a.clear();
}
}