Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTcpSocket Client fails to sends second send packet
Qt 6.11 is out! See what's new in the release blog

QTcpSocket Client fails to sends second send packet

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ion_knight
    wrote on last edited by
    #1

    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();@
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should rather use disconnectFromHost than close

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved