QTcpSocket Client fails to sends second send packet
-
Here is my code below, currently when I use this code below the responses from the server are correct. However when I try to write to messages to be sent to the server in a single socket the second response is not received. Does anyone have an idea how to implement this correctly? At the very bottom is my attempt at sending two messages one after the other, which fails, if anyone has an idea why this is happening that would be great. Thanks
sockettest.h
@#ifndef SOCKETTEST_H
#define SOCKETTEST_H#include <QObject>
#include <QTcpSocket>
#include <QDebug>
#include <iostream>class Sockettest : public QObject
{
Q_OBJECT
public:
explicit Sockettest(QObject *parent = 0);void connect();
signals:
public slots:
private:
QTcpSocket *socket;};
#endif // SOCKETTEST_H@
sockettest.cpp
@void Sockettest::connect()
{
socket = new QTcpSocket(this);socket->connectToHost("169.254.133.191",554); if(socket->waitForConnected(3000)) { //qDebug() << "connected"; // send std::cout << socket->write("REDIRECT: rtsp://169.254.133.191/output RTSP/1.0\r\n" "CSeq: 1\r\n" "Location: rtsp://169.254.133.190\r\n" "Authorization: Leeds Road North\r\n" "Require: display-inhibit\r\n"); socket->waitForBytesWritten(1000); socket->waitForReadyRead(3000); qDebug() << "Reading:" << socket->bytesAvailable(); qDebug() << socket->readAll(); socket->close(); socket = new QTcpSocket(this); socket->connectToHost("169.254.133.191",554); if(socket->waitForConnected(3000)) { //qDebug() << "connected"; // send std::cout << socket->write("GET_PARAMETER: rtsp://169.254.133.191/output RTSP/1.0\r\n" "CSeq: 2\r\n" "Content-type: text/parameters\r\n" "Session: 85be00\r\n" "Content-length: 152\r\n" "\r\n" "vclient_status\r\n" ); socket->waitForBytesWritten(1000); socket->waitForReadyRead(3000); qDebug() << "Reading:" << socket->bytesAvailable(); qDebug() << socket->readAll(); socket->close(); } } else { qDebug() << "Not Connected"; }
}@
Code Insert from sockettest.cpp (old method)
@ std::cout << socket->write("REDIRECT: rtsp://169.254.133.191/output RTSP/1.0\r\n"
"CSeq: 1\r\n"
"Location: rtsp://169.254.133.190\r\n"
"Authorization: Leeds Road North\r\n"
"Require: display-inhibit\r\n");socket->waitForBytesWritten(1000); socket->waitForReadyRead(3000); qDebug() << "Reading:" << socket->bytesAvailable(); qDebug() << socket->readAll(); std::cout << socket->write("GET_PARAMETER: rtsp://169.254.133.191/output RTSP/1.0\r\n" "CSeq: 2\r\n" "Content-type: text/parameters\r\n" "Session: 85be00\r\n" "Content-length: 152\r\n" "\r\n" "vclient_status\r\n" ); socket->waitForBytesWritten(1000); socket->waitForReadyRead(3000); qDebug() << "Reading:" << socket->bytesAvailable(); qDebug() << socket->readAll(); socket->close();@
-
Hi,
You should rather use disconnectFromHost than close