Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, February 2008
QTcpServer's incomingConnection not being called


Message 1 in thread

QT4.3.1 + VC6

Hi there,

I am trying to implement a simple TCP server, called CWittyServer, which
inherits the QTcpServer. The server is running ok on port 5300, as I can
check at my firewall (and also from a qDebug message), but it seems that
incomingConnection is not being called when client tries to connect. Here is
the CWittyServer prototype:

class CWittyServer : public QTcpServer{
Q_OBJECT
    public:
        CWittyServer(QObject *parent = 0);
    protected:
        void incomingConnection(int socketDescriptor);
    private:
        QStringList fortunes;
    signals:
        void signalMessage(const QString&);
};

And this is the code where the server is initialized.

    TcpServer = new CWittyServer();
    connect(TcpServer, SIGNAL(signalMessage(const QString &)), this,
SLOT(wtMessage(const QString &)));
    if(TcpServer->listen(QHostAddress(QHostAddress::Any),5300)) {
            qDebug("ok");
    }


Does any one can give me a tip of what it is going wrong?

Thanks in advance,

Flávio Mello

Message 2 in thread

This should work for you:

#include "server.h"

//////////////////////////////////////////////////////////////////////////////
CServer::CServer(QObject *parent) : QTcpServer(parent)
{
    cout << "CServer::CServer" << endl;

    if (!listen(QHostAddress::LocalHost, 4444)) {
        cout << "Unable to start the server: " << endl;
        close();
        return;
    }  
}



//////////////////////////////////////////////////////////////////////////////
void CServer::incomingConnection(int socketId)
{
    ClientConn * conn = new ClientConn(this);
    conn->setSocketDescriptor(socketId);
}



Flávio Luis de Mello escribió:
> QT4.3.1 + VC6
>
> Hi there,
>
> I am trying to implement a simple TCP server, called CWittyServer, 
> which inherits the QTcpServer. The server is running ok on port 5300, 
> as I can check at my firewall (and also from a qDebug message), but it 
> seems that incomingConnection is not being called when client tries to 
> connect. Here is the CWittyServer prototype:
>
> class CWittyServer : public QTcpServer{
> Q_OBJECT
>     public:
>         CWittyServer(QObject *parent = 0);
>     protected:
>         void incomingConnection(int socketDescriptor);
>     private:
>         QStringList fortunes;
>     signals:
>         void signalMessage(const QString&);
> };
>
> And this is the code where the server is initialized.
>
>     TcpServer = new CWittyServer();
>     connect(TcpServer, SIGNAL(signalMessage(const QString &)), this, 
> SLOT(wtMessage(const QString &)));
>     if(TcpServer->listen(QHostAddress(QHostAddress::Any),5300)) {
>             qDebug("ok");
>     }
>
>
> Does any one can give me a tip of what it is going wrong?
>
> Thanks in advance,
>
> Flávio Mello


-- 
 [ signature omitted ] 

Message 3 in thread

In fact, both your code and my code are able to make the server start
listening. My incomingConnection is not being called anyway, although my
server is derived from QTcpServer. I have replaced my code for your code and
it seems to have the same behavior. It listen, but doesn't respond to the
incoming connection.

Do you have any idea of waht is going wrong?

Thanks in advance,

Flávio Mello




On Thu, Feb 7, 2008 at 5:24 AM, Angel Ivan Castell <aicastell@xxxxxxxxxxxxxx>
wrote:

>
> This should work for you:
>
> #include "server.h"
>
>
> //////////////////////////////////////////////////////////////////////////////
> CServer::CServer(QObject *parent) : QTcpServer(parent)
> {
>    cout << "CServer::CServer" << endl;
>
>    if (!listen(QHostAddress::LocalHost, 4444)) {
>        cout << "Unable to start the server: " << endl;
>        close();
>        return;
>    }
> }
>
>
>
>
> //////////////////////////////////////////////////////////////////////////////
> void CServer::incomingConnection(int socketId)
> {
>    ClientConn * conn = new ClientConn(this);
>    conn->setSocketDescriptor(socketId);
> }
>
>
>
> Flávio Luis de Mello escribió:
> > QT4.3.1 + VC6
> >
> > Hi there,
> >
> > I am trying to implement a simple TCP server, called CWittyServer,
> > which inherits the QTcpServer. The server is running ok on port 5300,
> > as I can check at my firewall (and also from a qDebug message), but it
> > seems that incomingConnection is not being called when client tries to
> > connect. Here is the CWittyServer prototype:
> >
> > class CWittyServer : public QTcpServer{
> > Q_OBJECT
> >     public:
> >         CWittyServer(QObject *parent = 0);
> >     protected:
> >         void incomingConnection(int socketDescriptor);
> >     private:
> >         QStringList fortunes;
> >     signals:
> >         void signalMessage(const QString&);
> > };
> >
> > And this is the code where the server is initialized.
> >
> >     TcpServer = new CWittyServer();
> >     connect(TcpServer, SIGNAL(signalMessage(const QString &)), this,
> > SLOT(wtMessage(const QString &)));
> >     if(TcpServer->listen(QHostAddress(QHostAddress::Any),5300)) {
> >             qDebug("ok");
> >     }
> >
> >
> > Does any one can give me a tip of what it is going wrong?
> >
> > Thanks in advance,
> >
> > Flávio Mello
>
>
> --
> Ivan Castell Rovira
> -------------------------------------------------------------------
> CIRCONTROL, S.A.
> Lepanto, 43
> 08223 - Terrassa
> SPAIN
> Tel. +34 937362940
> Fax. +34 937362941
> E.mail: aicastell@xxxxxxxxxxxxxx
> WEB: www.circontrol.com
> -------------------------------------------------------------------
>
>

Message 4 in thread

Thy this:

//////////////////////////////////////////////////////////////////////////////
ClientConn::ClientConn(QObject *parent)
{
    connect(this, SIGNAL(readyRead()),    this, SLOT(readClientRequest()));

    connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));

    buffSize = 0;

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(startServing()));
}


//////////////////////////////////////////////////////////////////////////////
void ClientConn::readClientRequest()
{
    QDataStream in(this);
    in.setVersion(QDataStream::Qt_4_3);
    if (buffSize == 0) {
        if (bytesAvailable() < sizeof(quint16)) {
            return;
        }
        in >> buffSize;
    }  

    if (bytesAvailable() < buffSize) {
        return;
    }  

    QString requestType;

    in >> requestType;

    // ...

    buffSize = 0;
}


//////////////////////////////////////////////////////////////////////////////
void ClientConn::startServing()
{
    cout << "ClientConn::startServing" << endl;
    // ...
}


Flávio Luis de Mello escribió:
> In fact, both your code and my code are able to make the server start 
> listening. My incomingConnection is not being called anyway, although 
> my server is derived from QTcpServer. I have replaced my code for your 
> code and it seems to have the same behavior. It listen, but doesn't 
> respond to the incoming connection.
>
> Do you have any idea of waht is going wrong?
>
> Thanks in advance,
>
> Flávio Mello
>
>
>
>
> On Thu, Feb 7, 2008 at 5:24 AM, Angel Ivan Castell 
> <aicastell@xxxxxxxxxxxxxx <mailto:aicastell@xxxxxxxxxxxxxx>> wrote:
>
>
>     This should work for you:
>
>     #include "server.h"
>
>     //////////////////////////////////////////////////////////////////////////////
>     CServer::CServer(QObject *parent) : QTcpServer(parent)
>     {
>        cout << "CServer::CServer" << endl;
>
>        if (!listen(QHostAddress::LocalHost, 4444)) {
>            cout << "Unable to start the server: " << endl;
>            close();
>            return;
>        }
>     }
>
>
>
>     //////////////////////////////////////////////////////////////////////////////
>     void CServer::incomingConnection(int socketId)
>     {
>        ClientConn * conn = new ClientConn(this);
>        conn->setSocketDescriptor(socketId);
>     }
>
>
>
>     Flávio Luis de Mello escribió:
>     > QT4.3.1 + VC6
>     >
>     > Hi there,
>     >
>     > I am trying to implement a simple TCP server, called CWittyServer,
>     > which inherits the QTcpServer. The server is running ok on port
>     5300,
>     > as I can check at my firewall (and also from a qDebug message),
>     but it
>     > seems that incomingConnection is not being called when client
>     tries to
>     > connect. Here is the CWittyServer prototype:
>     >
>     > class CWittyServer : public QTcpServer{
>     > Q_OBJECT
>     >     public:
>     >         CWittyServer(QObject *parent = 0);
>     >     protected:
>     >         void incomingConnection(int socketDescriptor);
>     >     private:
>     >         QStringList fortunes;
>     >     signals:
>     >         void signalMessage(const QString&);
>     > };
>     >
>     > And this is the code where the server is initialized.
>     >
>     >     TcpServer = new CWittyServer();
>     >     connect(TcpServer, SIGNAL(signalMessage(const QString &)), this,
>     > SLOT(wtMessage(const QString &)));
>     >     if(TcpServer->listen(QHostAddress(QHostAddress::Any),5300)) {
>     >             qDebug("ok");
>     >     }
>     >
>     >
>     > Does any one can give me a tip of what it is going wrong?
>     >
>     > Thanks in advance,
>     >
>     > Flávio Mello
>
>
>     --
>     Ivan Castell Rovira
>     -------------------------------------------------------------------
>     CIRCONTROL, S.A.
>     Lepanto, 43
>     08223 - Terrassa
>     SPAIN
>     Tel. +34 937362940
>     Fax. +34 937362941
>     E.mail: aicastell@xxxxxxxxxxxxxx <mailto:aicastell@xxxxxxxxxxxxxx>
>     WEB: www.circontrol.com <http://www.circontrol.com>
>     -------------------------------------------------------------------
>
>


-- 
 [ signature omitted ] 

Message 5 in thread

I believe that the problem is previous to the ClientConn since the "void
CServer::incomingConnection(int socketId)" is not being called.




On Thu, Feb 7, 2008 at 11:32 AM, Angel Ivan Castell <
aicastell@xxxxxxxxxxxxxx> wrote:

>
> Thy this:
>
>
> //////////////////////////////////////////////////////////////////////////////
> ClientConn::ClientConn(QObject *parent)
> {
>    connect(this, SIGNAL(readyRead()),    this, SLOT(readClientRequest()));
>
>    connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
>
>    buffSize = 0;
>
>    timer = new QTimer(this);
>    connect(timer, SIGNAL(timeout()), this, SLOT(startServing()));
> }
>
>
>
> //////////////////////////////////////////////////////////////////////////////
> void ClientConn::readClientRequest()
> {
>    QDataStream in(this);
>    in.setVersion(QDataStream::Qt_4_3);
>    if (buffSize == 0) {
>        if (bytesAvailable() < sizeof(quint16)) {
>            return;
>        }
>        in >> buffSize;
>    }
>
>    if (bytesAvailable() < buffSize) {
>        return;
>    }
>
>    QString requestType;
>
>    in >> requestType;
>
>    // ...
>
>    buffSize = 0;
> }
>
>
>
> //////////////////////////////////////////////////////////////////////////////
> void ClientConn::startServing()
> {
>    cout << "ClientConn::startServing" << endl;
>    // ...
> }
>
>
> Flávio Luis de Mello escribió:
> > In fact, both your code and my code are able to make the server start
> > listening. My incomingConnection is not being called anyway, although
> > my server is derived from QTcpServer. I have replaced my code for your
> > code and it seems to have the same behavior. It listen, but doesn't
> > respond to the incoming connection.
> >
> > Do you have any idea of waht is going wrong?
> >
> > Thanks in advance,
> >
> > Flávio Mello
> >
> >
> >
> >
> > On Thu, Feb 7, 2008 at 5:24 AM, Angel Ivan Castell
> > <aicastell@xxxxxxxxxxxxxx <mailto:aicastell@xxxxxxxxxxxxxx>> wrote:
> >
> >
> >     This should work for you:
> >
> >     #include "server.h"
> >
> >
> //////////////////////////////////////////////////////////////////////////////
> >     CServer::CServer(QObject *parent) : QTcpServer(parent)
> >     {
> >        cout << "CServer::CServer" << endl;
> >
> >        if (!listen(QHostAddress::LocalHost, 4444)) {
> >            cout << "Unable to start the server: " << endl;
> >            close();
> >            return;
> >        }
> >     }
> >
> >
> >
> >
> //////////////////////////////////////////////////////////////////////////////
> >     void CServer::incomingConnection(int socketId)
> >     {
> >        ClientConn * conn = new ClientConn(this);
> >        conn->setSocketDescriptor(socketId);
> >     }
> >
> >
> >
> >     Flávio Luis de Mello escribió:
> >     > QT4.3.1 + VC6
> >     >
> >     > Hi there,
> >     >
> >     > I am trying to implement a simple TCP server, called CWittyServer,
> >     > which inherits the QTcpServer. The server is running ok on port
> >     5300,
> >     > as I can check at my firewall (and also from a qDebug message),
> >     but it
> >     > seems that incomingConnection is not being called when client
> >     tries to
> >     > connect. Here is the CWittyServer prototype:
> >     >
> >     > class CWittyServer : public QTcpServer{
> >     > Q_OBJECT
> >     >     public:
> >     >         CWittyServer(QObject *parent = 0);
> >     >     protected:
> >     >         void incomingConnection(int socketDescriptor);
> >     >     private:
> >     >         QStringList fortunes;
> >     >     signals:
> >     >         void signalMessage(const QString&);
> >     > };
> >     >
> >     > And this is the code where the server is initialized.
> >     >
> >     >     TcpServer = new CWittyServer();
> >     >     connect(TcpServer, SIGNAL(signalMessage(const QString &)),
> this,
> >     > SLOT(wtMessage(const QString &)));
> >     >     if(TcpServer->listen(QHostAddress(QHostAddress::Any),5300)) {
> >     >             qDebug("ok");
> >     >     }
> >     >
> >     >
> >     > Does any one can give me a tip of what it is going wrong?
> >     >
> >     > Thanks in advance,
> >     >
> >     > Flávio Mello
> >
> >
> >     --
> >     Ivan Castell Rovira
> >     -------------------------------------------------------------------
> >     CIRCONTROL, S.A.
> >     Lepanto, 43
> >     08223 - Terrassa
> >     SPAIN
> >     Tel. +34 937362940
> >     Fax. +34 937362941
> >     E.mail: aicastell@xxxxxxxxxxxxxx <mailto:aicastell@xxxxxxxxxxxxxx>
> >     WEB: www.circontrol.com <http://www.circontrol.com>
> >     -------------------------------------------------------------------
> >
> >
>
>
> --
> Ivan Castell Rovira
> -------------------------------------------------------------------
> CIRCONTROL, S.A.
> Lepanto, 43
> 08223 - Terrassa
> SPAIN
> Tel. +34 937362940
> Fax. +34 937362941
> E.mail: aicastell@xxxxxxxxxxxxxx
> WEB: www.circontrol.com
> -------------------------------------------------------------------
>
>

Message 6 in thread

Hi Flávio.

The code attached before works for me. If you can attach me some simple 
testing code
reproducing your problem I will try to fix your bug (it should be simple).

  -- Ivan

Flávio Luis de Mello escribió:
> In fact, both your code and my code are able to make the server start 
> listening. My incomingConnection is not being called anyway, although 
> my server is derived from QTcpServer. I have replaced my code for your 
> code and it seems to have the same behavior. It listen, but doesn't 
> respond to the incoming connection.
>
> Do you have any idea of waht is going wrong?
>
> Thanks in advance,
>
> Flávio Mello
>
>
>
>
> On Thu, Feb 7, 2008 at 5:24 AM, Angel Ivan Castell 
> <aicastell@xxxxxxxxxxxxxx <mailto:aicastell@xxxxxxxxxxxxxx>> wrote:
>
>
>     This should work for you:
>
>     #include "server.h"
>
>     //////////////////////////////////////////////////////////////////////////////
>     CServer::CServer(QObject *parent) : QTcpServer(parent)
>     {
>        cout << "CServer::CServer" << endl;
>
>        if (!listen(QHostAddress::LocalHost, 4444)) {
>            cout << "Unable to start the server: " << endl;
>            close();
>            return;
>        }
>     }
>
>
>
>     //////////////////////////////////////////////////////////////////////////////
>     void CServer::incomingConnection(int socketId)
>     {
>        ClientConn * conn = new ClientConn(this);
>        conn->setSocketDescriptor(socketId);
>     }
>
>
>
>     Flávio Luis de Mello escribió:
>     > QT4.3.1 + VC6
>     >
>     > Hi there,
>     >
>     > I am trying to implement a simple TCP server, called CWittyServer,
>     > which inherits the QTcpServer. The server is running ok on port
>     5300,
>     > as I can check at my firewall (and also from a qDebug message),
>     but it
>     > seems that incomingConnection is not being called when client
>     tries to
>     > connect. Here is the CWittyServer prototype:
>     >
>     > class CWittyServer : public QTcpServer{
>     > Q_OBJECT
>     >     public:
>     >         CWittyServer(QObject *parent = 0);
>     >     protected:
>     >         void incomingConnection(int socketDescriptor);
>     >     private:
>     >         QStringList fortunes;
>     >     signals:
>     >         void signalMessage(const QString&);
>     > };
>     >
>     > And this is the code where the server is initialized.
>     >
>     >     TcpServer = new CWittyServer();
>     >     connect(TcpServer, SIGNAL(signalMessage(const QString &)), this,
>     > SLOT(wtMessage(const QString &)));
>     >     if(TcpServer->listen(QHostAddress(QHostAddress::Any),5300)) {
>     >             qDebug("ok");
>     >     }
>     >
>     >
>     > Does any one can give me a tip of what it is going wrong?
>     >
>     > Thanks in advance,
>     >
>     > Flávio Mello
>
>
>     --
>     Ivan Castell Rovira
>     -------------------------------------------------------------------
>     CIRCONTROL, S.A.
>     Lepanto, 43
>     08223 - Terrassa
>     SPAIN
>     Tel. +34 937362940
>     Fax. +34 937362941
>     E.mail: aicastell@xxxxxxxxxxxxxx <mailto:aicastell@xxxxxxxxxxxxxx>
>     WEB: www.circontrol.com <http://www.circontrol.com>
>     -------------------------------------------------------------------
>
>


-- 
 [ signature omitted ]