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. Grabbing Data in QTcpServer from incoming connection
QtWS25 Last Chance

Grabbing Data in QTcpServer from incoming connection

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.6k Views
  • 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.
  • C Offline
    C Offline
    cr4y88
    wrote on last edited by
    #1

    Hello....

    I created 2 projects separately. The first program is the client project and the second is the server project.
    On client project I have a class with the name ClientTCP that is derived from QTcpSocket, then on server project I have a class with the name SocketServer which is derived from QTcpServer

    I tried it with the connection. It works. but when I want to grab the data it didnt work.

    On class ClientTCP. I want to send a data using TextStream. The code looks like this:
    @
    void ClientTCP::sendText(QString text)
    {
    QTextStream out(this);
    out << text;
    this->waitForBytesWritten();
    }
    @

    I want to grab this data that was sent by ClientTCP in my client project on the class SocketServer in my server project. But I have no luck getting the data since it's on another program and I cant include the class since it should stay on the client project.

    Can somebody help me?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Without the code from your server it's pretty much Crystal Ball Debugging. How do you handle the connection on the other side ?

      On a side note, you don't need to subclass QTcpSocket in most of the cases, just use a QTcpSocket as member of your Client class

      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
      • C Offline
        C Offline
        cr4y88
        wrote on last edited by
        #3

        Thx for answering. I got it working now, Thanks.

        I got another problem. The problem is that if I close the client program. I dont get any notification at all, eventhough I already put a notification when a SIGNAL(disconnected()) is emitted.

        Here is the code:
        @
        Server::Server(QObject *parent) :
        QObject(parent)
        {
        server = new SocketServer(this);
        connect(server,SIGNAL(newClientConnection()),SLOT(newClientConnection()));
        }

        void Server::newClientConnection()
        {
        qDebug() << "New Connection";

        client = server->nextPendingConnection();
        connect(client, SIGNAL(disconnected()), this, SLOT(connectionClosed()));
        

        }

        void ServerConnector::connectionClosed()
        {
        qDebug() << "Client closed connection";
        }

        @

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Are you properly disconnecting from the client side ?

          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
          • C Offline
            C Offline
            cr4y88
            wrote on last edited by
            #5

            Hello...

            Sry for late reply. What I do is I just close the client app. I have another server that was builded using qt3. The server runs perfectly with qt3 since it's there was a signal connectionclosed, but this is not the case in qtcpsocket. I saw some example and implement it the project but it seems didnt work for me.

            Another problem I face is:
            I need to connect this server A which I make using qtcpserver to another server B which don't use qt at all, The server B is coded using C/C++. The problem is I dont know the structure of the server B. Since I only have a server itself and no code for this at all. My question is: is there a way to connect it? if it does, how?

            Thanks

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Sounds like a strange behavior

              Depending on what you want from that server your can use QNetworkAccessManager.

              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