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. QTcpServer - different behvaior in debug & release
Forum Updated to NodeBB v4.3 + New Features

QTcpServer - different behvaior in debug & release

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtcpservernetworkrelease mode
17 Posts 2 Posters 6.3k 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    hi
    This is on the same PC?
    Its 100% sure its not firewall or scanner related?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      reezeus
      wrote on last edited by
      #3

      Hi mrjj

      Clients and server are not on the same PC.
      If it was due to the firewall, I assume it would be the same issue in both debug & release?

      mrjjM 1 Reply Last reply
      0
      • R reezeus

        Hi mrjj

        Clients and server are not on the same PC.
        If it was due to the firewall, I assume it would be the same issue in both debug & release?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #4

        @reezeus said:
        I mean when u run in release vs debug.
        same pc?

        Well the actual exe would be different so say the debug was "accepted" and release not.

        For some security solutions just the fact that is located in another folder would be
        enough.

        Its seems very odd so just asking if u tested with firewall off, just be sure.
        (NetSh Advfirewall set allprofiles state off)

        1 Reply Last reply
        0
        • R Offline
          R Offline
          reezeus
          wrote on last edited by
          #5

          Didn't get it right indeed: yes debug & release are both tested on the same PC.
          Both versions are in the same directory (the one created by default by Qt): one folder for the debug and one folder for release.
          Note that the issue arises before I deploy the app, i.e. just by starting the program from within the release folder.
          I have tried several clean/run qmake/build all.

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

            What if u run directly in VS ?

            1 Reply Last reply
            0
            • R Offline
              R Offline
              reezeus
              wrote on last edited by
              #7

              I don't think I can run my Qt code in VS, I believe I first need to install the VS plugin for Qt?
              I've never compiled Qt code with VS, I use Qt only with Qt creator.

              mrjjM 1 Reply Last reply
              0
              • R reezeus

                I don't think I can run my Qt code in VS, I believe I first need to install the VS plugin for Qt?
                I've never compiled Qt code with VS, I use Qt only with Qt creator.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @reezeus
                Ok. well if u run from in Creator in release mode, it also does this?

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  reezeus
                  wrote on last edited by
                  #9

                  Yes, same behavior..

                  mrjjM 1 Reply Last reply
                  0
                  • R reezeus

                    Yes, same behavior..

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @reezeus
                    can you reproduce this in small sample?
                    Might be a bug then.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      reezeus
                      wrote on last edited by
                      #11

                      Sure, will do this when I have some time. Where should I upload the files?

                      mrjjM 1 Reply Last reply
                      0
                      • R reezeus

                        Sure, will do this when I have some time. Where should I upload the files?

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @reezeus
                        There is no upload function here.
                        I use dropbox as it very easy to share.

                        But if sample very small, its fine to post directly.

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          reezeus
                          wrote on last edited by reezeus
                          #13

                          .h file:
                          #ifndef IPSERVER
                          #define IPSERVER
                          #define HEADER_FENSERVEUR

                          #include <QtWidgets>
                          #include <QtNetwork>
                          #include "emailoutlook.h"

                          class IPServer : public QWidget
                          {
                          Q_OBJECT

                          public:
                              IPServer();
                              void SendToAll(const QString &message);
                          
                          private slots:
                              void NewConnection();
                              void DataReceived();
                              void DisconnectClient();
                          
                          private:
                              EmailOutlook outApp;
                              QTcpServer *server;
                              QList<QTcpSocket *> clients;
                              quint16 sizeMessage;
                          

                          };

                          #endif // IPSERVER

                          .cpp file:
                          #include "ipserver.h"

                          IPServer::IPServer()
                          {
                          outApp = EmailOutlook();
                          server = new QTcpServer(this);
                          if (!server->listen(QHostAddress::Any, 50869))
                          {
                          qDebug() << "Server cound not start" + server->errorString();
                          }
                          else
                          {
                          qDebug() << "Server has started on port " + QString::number(server->serverPort()) + ". Clients can now connect.";
                          connect(server, SIGNAL(newConnection()), this, SLOT(NewConnection()));
                          }

                          sizeMessage = 0;
                          

                          }

                          void IPServer::NewConnection()
                          {
                          //SendToAll("New Client connected");

                          QTcpSocket *newClient = server->nextPendingConnection();
                          clients << newClient;
                          SendToAll("New Client connected");
                          connect(newClient, SIGNAL(readyRead()), this, SLOT(DataReceived()));
                          connect(newClient, SIGNAL(disconnected()), this, SLOT(DisconnectClient()));
                          

                          }

                          void IPServer::DataReceived()
                          {
                          QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
                          if (socket == 0)
                          return;

                          QDataStream in(socket);
                          
                          if (sizeMessage == 0)
                          {
                              if (socket->bytesAvailable() < (int)sizeof(quint16))
                                   return;
                          
                              in >> sizeMessage;
                          }
                          
                          if (socket->bytesAvailable() < sizeMessage)
                              return;
                          
                          QString message;
                          in >> message;
                          
                          SendToAll(message);
                          
                          sizeMessage = 0;
                          

                          }

                          void IPServer::DisconnectClient()
                          {
                          SendToAll("New client disconnected");

                          QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
                          if (socket == 0)
                              return;
                          
                          clients.removeOne(socket);
                          socket->deleteLater();
                          

                          }

                          void IPServer::SendToAll(const QString &message)
                          {
                          QByteArray paquet;
                          QDataStream out(&paquet, QIODevice::WriteOnly);

                          out << (quint16) 0;
                          out << message;
                          out.device()->seek(0);
                          out << (quint16) (paquet.size() - sizeof(quint16));
                          
                          for (int i = 0; i < clients.size(); i++)
                          {
                              clients[i]->write(paquet);
                          }
                          

                          }

                          The IPServer class is initialized from another class:
                          IPServer *myServer;
                          myServer = new IPServer();

                          1 Reply Last reply
                          0
                          • mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            ok.
                            This code can someone else run and see if it can reproduced on other pc?

                            1 Reply Last reply
                            0
                            • R Offline
                              R Offline
                              reezeus
                              wrote on last edited by
                              #15

                              I have recompiled on another PC with Qt version 5.5.0 (still mvsc2013 compiler) and it works fine; debug, release & deployed.

                              mrjjM 1 Reply Last reply
                              0
                              • R reezeus

                                I have recompiled on another PC with Qt version 5.5.0 (still mvsc2013 compiler) and it works fine; debug, release & deployed.

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                @reezeus said:
                                so it seems to be Qt 5.5.1 related ?
                                I dont have VS compiler so cant check here.

                                1 Reply Last reply
                                0
                                • R Offline
                                  R Offline
                                  reezeus
                                  wrote on last edited by
                                  #17

                                  It could be. Although it was working fine in previous release with Qt 5.5.1.

                                  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