Results 1 to 3 of 3

Thread: QTcpServer Problem

  1. #1
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QTcpServer Problem

    My question is simple, I suppose, but I can't figure out why this is happening.

    I have a QTcpServer:

    Qt Code:
    1. //server initialization
    2. server= new QTcpServer();
    3. bool success = server->listen(QHostAddress::Any, 10101);
    4.  
    5. if(!success)
    6. {
    7. ui->textEdit->setTextColor(Qt::red);
    8. ui->textEdit->append(" > Could not create TopMovie Server! \n Reason: TopMovie Server is already running! \n\n This Window will automatically close!");
    9. ui->textEdit->setTextColor(Qt::black);
    10. QTimer *timer = new QTimer(this);
    11. connect(timer, SIGNAL(timeout()), this, SLOT(sterge_server()));
    12. timer->start(3000);
    13. }
    14. else
    15. {
    16. ui->textEdit->setTextColor(Qt::white);
    17. ui->textEdit->append(" > TopMovie Server Online!");
    18. connect(server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
    19. ui->textEdit->setTextColor(Qt::black);
    20. DataBase();
    21. }
    22.  
    23. //incomingConnection
    24. void TopMovieS::incomingConnection()
    25. {
    26. int Socketfd=server->nextPendingConnection()->socketDescriptor();
    27. QTcpSocket *client = new QTcpSocket(this);
    28. client->setSocketDescriptor(Socketfd);
    29. clients.insert(client);
    30.  
    31. string adresa=" > New client from: "+client->peerAddress().toString().toStdString();
    32. ui->textEdit->setTextColor(Qt::yellow);
    33. ui->textEdit->append(adresa.c_str());
    34. ui->textEdit->setTextColor(Qt::black);
    35.  
    36. connect(client, SIGNAL(readyRead()), this, SLOT(readyRead()));
    37. connect(client, SIGNAL(disconnected()), this, SLOT(disconnected()));
    38. }
    To copy to clipboard, switch view to plain text mode 

    I read on QTcpServer Documentation that I have to call nextPendingConnection() instead of IncommingConnection(). And also IncommingConnection() needs a QTcpSocket parameter... Anyway, this code on Windows gives a warning every time a new client is connecting: "QSocketNotifier: Multiple socket notifiers for same socket 768 and type Read", but it still works.

    On Ubuntu the same code doesn't work. It gives the same error, but doesn't continue: "QSocketNotifier: Invalid socket 24 and type 'Read', disabling..."

    Please help me, I am new to Qt and this is my first QTcpServer. I didn't understood everything from documentation, so the code is, I suppose, wrong.

    Thank you!

  2. #2
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer Problem

    "QSocketNotifier: Multiple socket notifiers for same socket 768 and type Read" warning tells you that there are multiple QTcpSocket instances that use the same socket descriptor.

    Instead of doing this:

    Qt Code:
    1. int Socketfd=server->nextPendingConnection()->socketDescriptor();
    2. QTcpSocket *client = new QTcpSocket(this);
    3. client->setSocketDescriptor(Socketfd);
    To copy to clipboard, switch view to plain text mode 

    try this:

    Qt Code:
    1. QTcpSocket *client = server->nextPendingConnection();
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to stillwaiting for this useful post:

    ionutdanila (27th December 2010)

  4. #3
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: QTcpServer Problem

    @stillwaiting Thank you very very much! It works now!

Similar Threads

  1. QTcpServer QTcpSocket problem
    By jmsbc in forum Qt Programming
    Replies: 0
    Last Post: 20th November 2009, 17:42
  2. QTcpSocket, QTcpServer problem
    By frido in forum Qt Programming
    Replies: 3
    Last Post: 3rd April 2009, 23:16
  3. Qtcpserver problem
    By kingslee in forum Qt Programming
    Replies: 3
    Last Post: 3rd September 2008, 18:34
  4. QTcpServer problem in Python Qt
    By mejustme in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2008, 14:49
  5. Replies: 1
    Last Post: 18th June 2006, 10:12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.