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. No reception of NewConnection signal
Qt 6.11 is out! See what's new in the release blog

No reception of NewConnection signal

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 9.4k 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.
  • C Offline
    C Offline
    cyte13
    wrote on last edited by
    #3

    Thanks for your reply, it is what I think, but doesn' work...
    Here is the threated version one:

    I have my own CGameEngine class derivated from QThread which has as a member a pointeur to another class CGameEngineServer which derivated from QTcpServer:

    GAMEENGINE:
    @
    class GAMEENGINE_EXPORT CGameEngine : public QThread
    {
    Q_OBJECT
    public:
    /** Constructeur par défaut */
    CGameEngine(QObject *parent = 0);

    /** Destructeur */
    ~CGameEngine();
    
    /** 
        StartProcess    :    Lance le serveur de jeu local et gère la partie
        engineport        :    Port d'écoute du serveur local de jeu
        placeavailable    :    Nombre maximum de joueur à la table
        RETURN            :    GAMEENGINE_CORRECT ou GAMEENGINE_ERREUR
    **/
    void StartProcess(quint16 engineport, int placeavailable);
    
    void run();
    

    private:
    //CComEngineBDD* MyComEngineBDD;
    CGameEngineServer* MyEngineServer;
    ...

    void CGameEngine::StartProcess(quint16 engineport, int placeavailable)
    {
    m_engineport = engineport;
    m_MaxPlayer = placeavailable;

    start();
    

    }

    void CGameEngine::run()
    {
    /* Create the server object /
    MyEngineServer = new CGameEngineServer();
    /
    Start listenning on port in arg /
    if (!MyEngineServer->Listen(m_engineport)) exit();
    /
    Connect signals between MyEngineServer and this to specify processes at a new incoming message */
    QObject::connect(MyEngineServer, SIGNAL(MessageToRead(QString)), this, SLOT(MessageToRead(QString)));
    exec();
    }
    @
    GAMEENGINESERVER:
    @
    class GAMENETWORK_EXPORT CGameEngineServer : public QTcpServer
    {
    Q_OBJECT

    public:
    CGameEngineServer(QObject *parent = 0);

    bool Listen(quint16 port);
    void Close();
    

    protected:
    //void incomingConnection(int socketDescriptor);

    private:
    QVector<QTcpSocket*> m_VectorClient;
    quint16 tailleMessage;

    signals:
    void MessageToRead(QString);

    public slots:
    void NewConnection();
    void ReadMessage();
    };

    bool CGameEngineServer::Listen(quint16 port)
    {
    bool result = listen(QHostAddress::LocalHost, port);
    if (result)
    {
    printf("Local Game Engine Server listenning on port %d...\n", port);
    /* make connection for a new connction */
    QObject::connect(this, SIGNAL(newConnection()), this, SLOT(NewConnection()));
    }
    else
    {
    printf("Unable for Local Game Engine Server to listen on port %d...\n", port);
    }
    return result;
    }

    @

    and now the call to StartProcess :
    @
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    CGameEngine MyGameEngine;
    MyGameEngine.StartProcess(8500, 2);

    return a.exec&#40;&#41;;
    

    }
    @

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tony
      wrote on last edited by
      #4

      Well, I've tried your code in my PC ... and it works :)

      Just a strange thing, but it's not dependent on your code. Qt Creator does not show printf messages in "Application Output". But if you launch your program in a console, you'll see the message (I put a printf in NewConnection slot).

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tony
        wrote on last edited by
        #5

        Btw ... use qDebug() function to show message in Application Output ...

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cyte13
          wrote on last edited by
          #6

          all my printf worked fine but NewConnection...
          As an example, at the start of listenning : printf("Local Game Engine Server listenning on port %d...\n", port); => works fine in the console....

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tony
            wrote on last edited by
            #7

            Well, your server starts fine (as netstat shows...)

            I just make a "telnet 127.0.0.1 8500" and a NEW CONNECTION!!! (my message) appears.

            Firewall? Do you connect to 127.0.0.1 and port 8500? I cannot see any other problem ...

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cyte13
              wrote on last edited by
              #8

              I desactived the firewall but nothing changed.
              What is strang is that the client correctly onnects to the server and intercepts the connected() signal.
              Moreover, I need to put the WaitForNewConnection() to be able to intercept newConnection() signal....

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cyte13
                wrote on last edited by
                #9

                telnet succeced in connecting to the server but still nothing in new connection!!!!

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tony
                  wrote on last edited by
                  #10

                  well, the only thing left is that I can post my code and you'll check for any diff ...

                  @
                  #ifndef GAMESERVER_H
                  #define GAMESERVER_H

                  #include <QtCore>
                  #include <QtNetwork>

                  class CGameEngineServer;

                  class CGameEngine : public QThread
                  {
                  Q_OBJECT

                  quint16 m_engineport;
                  

                  public:
                  /** Constructeur par défaut */
                  CGameEngine(QObject *parent = 0) : QThread(parent), MyEngineServer(0) { }

                  /** Destructeur */
                  ~CGameEngine() { }
                  
                  /**
                      StartProcess    :    Lance le serveur de jeu local et gère la partie
                      engineport        :    Port d'écoute du serveur local de jeu
                      placeavailable    :    Nombre maximum de joueur à la table
                      RETURN            :    GAMEENGINE_CORRECT ou GAMEENGINE_ERREUR
                  **/
                  void StartProcess(quint16 engineport, int placeavailable);
                  
                  void run();
                  

                  private:
                  CGameEngineServer* MyEngineServer;
                  };

                  class CGameEngineServer : public QTcpServer
                  {
                  Q_OBJECT

                  public:
                  CGameEngineServer(QObject *parent = 0) : QTcpServer(parent) { }

                  bool Listen(quint16 port);
                  void Close();
                  

                  protected:
                  //void incomingConnection(int socketDescriptor);

                  private:
                  QVector<QTcpSocket*> m_VectorClient;
                  quint16 tailleMessage;

                  signals:
                  void MessageToRead(QString);

                  public slots:
                  void NewConnection() { printf("NEW CONNECTION!!!\n"); }
                  void ReadMessage() { }
                  };

                  #endif // GAMESERVER_H
                  @

                  @
                  #include "gameserver.h"

                  void CGameEngine::StartProcess(quint16 engineport, int placeavailable)
                  {
                  m_engineport = engineport;
                  // m_MaxPlayer = placeavailable;

                  start();
                  

                  }

                  void CGameEngine::run()
                  {
                  /* Create the server object /
                  MyEngineServer = new CGameEngineServer();
                  /
                  Start listenning on port in arg /
                  if (!MyEngineServer->Listen(m_engineport)) exit();
                  /
                  Connect signals between MyEngineServer and this to specify processes at a new incoming message */
                  QObject::connect(MyEngineServer, SIGNAL(MessageToRead(QString)), this, SLOT(MessageToRead(QString)));
                  exec();
                  }

                  bool CGameEngineServer::Listen(quint16 port)
                  {
                  bool result = listen(QHostAddress::LocalHost, port);
                  if (result)
                  {
                  printf("Local Game Engine Server listenning on port %d...\n", port);
                  /* make connection for a new connction */
                  QObject::connect(this, SIGNAL(newConnection()), this, SLOT(NewConnection()));
                  }
                  else
                  {
                  printf("Unable for Local Game Engine Server to listen on port %d...\n", port);
                  }
                  return result;
                  }
                  @

                  @
                  #include <QtCore/QCoreApplication>

                  #include "gameserver.h"

                  int main(int argc, char *argv[])
                  {
                  QCoreApplication a(argc, argv);
                  CGameEngine MyGameEngine;
                  MyGameEngine.StartProcess(8500, 2);

                  return a.exec&#40;&#41;;
                  

                  }
                  @

                  I hope that this will help you solve your problem ...

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cyte13
                    wrote on last edited by
                    #11

                    not better.....
                    The only difference between your code and mine is that the CGameEngine and CGameEngineServer are available via a library (ifdef GAMENETWORK_LIB

                    define GAMENETWORK_EXPORT Q_DECL_EXPORT

                    #else

                    define GAMENETWORK_EXPORT Q_DECL_IMPORT

                    #endif)

                    ==> May cause the issue?

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      tony
                      wrote on last edited by
                      #12

                      I don't think so ... well, you can try :)

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        cyte13
                        wrote on last edited by
                        #13

                        I progress...
                        When removing all classes access by library and directly insert .h and .cpp files into my app folder, it workd fine!!!!

                        Thanks a lot.

                        But... I would like to understand why it does not work when using StartProcess from the CGameEngine got from a library...!!!!

                        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